public async Task <IActionResult> ActivateUserEmail(EmailAddressViewModel model) { if (ModelState.IsValid) { // 通过邮件地址查询用户地址 var user = await _userManager.FindByEmailAsync(model.Email); if (user != null) { if (!await _userManager.IsEmailConfirmedAsync(user)) { //生成电子邮件确认令牌 var token = await _userManager.GenerateEmailConfirmationTokenAsync(user); //生成电子邮件的确认链接 var confirmationLink = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, token }, Request.Scheme); _logger.Log(LogLevel.Warning, confirmationLink); ViewBag.Message = "如果你在我们系统有注册账户,我们已经发了邮件到您的邮箱中,请前往邮箱激活您的用户。"; //重定向用户到忘记密码确认视图 return(View("ActivateUserEmailConfirmation", ViewBag.Message)); } } } ViewBag.Message = "请确认邮箱是否存在异常,现在我们无法给您发送激活链接。"; // 为了避免帐户枚举和暴力攻击,所以不进行用户不存在或邮箱未验证的提示 return(View("ActivateUserEmailConfirmation", ViewBag.Message)); }
public async Task <IActionResult> ForgotPassword(EmailAddressViewModel model) { if (ModelState.IsValid) { // 通过邮件地址查询用户地址 var user = await _userManager.FindByEmailAsync(model.Email); // 如果找到了用户并且确认了电子邮件 if (user != null && await _userManager.IsEmailConfirmedAsync(user)) { //生成重置密码令牌 var token = await _userManager.GeneratePasswordResetTokenAsync(user); // 生成密码重置链接 var passwordResetLink = Url.Action("ResetPassword", "Account", new { email = model.Email, token = token }, Request.Scheme); // 将密码重置链接记录到文件中 _logger.Log(LogLevel.Warning, passwordResetLink); //重定向用户到忘记密码确认视图 return(View("ForgotPasswordConfirmation")); } // 为了避免帐户枚举和暴力攻击,所以不进行用户不存在或邮箱未验证的提示 return(View("ForgotPasswordConfirmation")); } return(View(model)); }
public ActionResult AddressTypePartial(AddressTypeViewModel model) { if (ModelState.IsValid && !String.IsNullOrWhiteSpace(model.CustomerID)) { switch (model.SelectedAddressType) { case "Email": var emailAddressModel = new EmailAddressViewModel() { CustomerID = model.CustomerID }; return(PartialView("CreateEmailAddressPartial", emailAddressModel)); case "Postal": var postalAddressModel = new PostalAddressEditViewModel() { CustomerID = model.CustomerID }; var countriesRepo = new CountriesRepository(); postalAddressModel.Countries = countriesRepo.GetCountries(); var regionsRepo = new RegionsRepository(); postalAddressModel.Regions = regionsRepo.GetRegions(); return(PartialView("CreatePostalAddressPartial", postalAddressModel)); default: return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }
public bool SaveEmailAddress(EmailAddressViewModel model) { if (model != null) { if (Guid.TryParse(model.CustomerID, out Guid newGuid) && !String.IsNullOrWhiteSpace(model.Email)) { using (var context = new ApplicationDbContext()) { var current = context.EmailAddresses.Find(model.Email.Trim()); if (current == null) { var emailAddress = new EmailAddress() { CustomerID = newGuid, Email = model.Email.Trim() }; context.EmailAddresses.Add(emailAddress); } else { current.CustomerID = newGuid; } context.SaveChanges(); return(true); } } } return(false); }
public async Task <IActionResult> CreateEmail( [Bind(emailProperties)] EmailAddressViewModel c) { if (!ModelState.IsValid) { return(View(c)); } c.ID = Guid.NewGuid().ToString(); var o = AddressObjectFactory.CreateEmail(c.ID, c.EmailAddress, c.ValidFrom, c.ValidTo); await addresses.AddObject(o); return(RedirectToAction("Index")); }
public ActionResult CreateEmailAddressPartial(EmailAddressViewModel model) { if (ModelState.IsValid) { var repo = new CustomersRepository(); bool saved = repo.SaveEmailAddress(model); if (saved) { return(RedirectToAction("Edit", new { id = model.CustomerID })); } } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }
public async Task <IActionResult> EditEmail([Bind(emailProperties)] EmailAddressViewModel c) { if (!ModelState.IsValid) { return(View("EditEmail", c)); } var o = await addresses.GetObject(c.ID) as EmailAddressObject; o.DbRecord.Address = c.EmailAddress; o.DbRecord.ValidFrom = c.ValidFrom ?? DateTime.MinValue; o.DbRecord.ValidTo = c.ValidTo ?? DateTime.MaxValue; await addresses.UpdateObject(o); return(RedirectToAction("Index")); }
public async Task <IActionResult> ForgotPassword(EmailAddressViewModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(model.Email); if (user != null && await _userManager.IsEmailConfirmedAsync(user)) { var token = await _userManager.GeneratePasswordResetTokenAsync(user); var passwordResetLink = Url.Action("ResetPassword", "Account", new { email = model.Email, token = token }, Request.Scheme); _logger.Log(LogLevel.Warning, passwordResetLink); return(View("ForgotPasswordConfirmation")); } return(View("ForgotPasswordConfirmation")); } return(View(model)); }
public async Task <IActionResult> ForgotPassword(EmailAddressViewModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(model.Email); if (user != null && !await _userManager.IsEmailConfirmedAsync(user)) { var token = await _userManager.GeneratePasswordResetTokenAsync(user); var resetLink = Url.Action("ResetPassword", "Account", new { email = model.Email, token = token }, Request.Scheme); ViewBag.Message = "如果你在系統已註冊帳戶,我們已發送郵件到信箱,請前往重置密碼"; return(View("ForgotPasswordConfirmation", ViewBag.Message)); } } ViewBag.Message = "請確認信箱是否異常"; return(View("ForgotPasswordConfirmation", ViewBag.Message)); }
public async Task <IActionResult> ActivateUserEmail(EmailAddressViewModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(model.Email); if (user != null && !await _userManager.IsEmailConfirmedAsync(user)) { var token = await _userManager.GenerateEmailConfirmationTokenAsync(user); var confirmLink = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, token = token }, Request.Scheme); ViewBag.Message = "如果你在系統已註冊帳戶,我們已發送郵件到信箱,請前往開通帳戶"; return(View("ActivateUserEmailConfirmation", ViewBag.Message)); } } ViewBag.Message = "請確認信箱是否異常"; return(View("ActivateUserEmailConfirmation", ViewBag.Message)); }
public async Task <IActionResult> ActivateUserEmail(EmailAddressViewModel model) { if (ModelState.IsValid) { var user = await userManager.FindByEmailAsync(model.Email); if (user != null) { if (!await userManager.IsEmailConfirmedAsync(user)) { //生成电子邮件确认令牌 var token = await userManager.GenerateEmailConfirmationTokenAsync(user); //生成电子邮件的确认链接 var confirmationLink = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, token = token }, Request.Scheme); logger.Log(LogLevel.Warning, confirmationLink); //ViewBag.Message = "如果你在我们系统有注册账户,我们已经发了邮件到您的邮箱中,请前往邮箱激活您的用户。"; StringBuilder strB = new StringBuilder(); strB.AppendLine("如果你在我们系统有注册账户,我们已经发了邮件到您的邮箱中,请前往邮箱激活您的用户。"); strB.AppendLine("链接为:"); ViewBag.LinkTitle = "激活邮箱"; ViewBag.LinkMessage = strB.ToString(); ViewBag.LinkPath = confirmationLink.ToString(); //重定向用户到忘记密码确认视图 return(View("Link")); } } ViewBag.Message = "请确认邮箱是否存在异常,现在我们无法给您发送激活链接。"; // 为了避免帐户枚举和暴力攻击,所以不进行用户不存在或邮箱未验证的提示 return(View("ActivateUserEmailConfirmation", ViewBag.Message)); } return(View()); }
public async Task <IActionResult> ActivateUserEmail(EmailAddressViewModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(model.Email); if (user != null) { if (!await _userManager.IsEmailConfirmedAsync(user)) { var token = await _userManager.GenerateEmailConfirmationTokenAsync(user); var confirmationLink = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, token = token }, Request.Scheme); //生成电子邮箱确认链接 _logger.Log(LogLevel.Warning, confirmationLink); ViewBag.Message = "邮件已发送到您的邮箱中,请前往邮箱激活您的账号"; return(View("ActivateUserEmailConfirmation", ViewBag.Message)); } } } ViewBag.Message = "请确认邮箱是否存在异常,现在无法发送激活链接"; return(View("ActivateUserEmailConfirmation", ViewBag.Message)); }
public EmailAddressViewModel GetEmailAddress(Guid customerid, string emailaddress) { if (customerid != Guid.Empty) { using (var context = new ApplicationDbContext()) { var emailAddress = context.EmailAddresses.AsNoTracking() .Where(x => x.CustomerID == customerid && x.Email == emailaddress.Trim()) .SingleOrDefault(); if (emailAddress != null && !String.IsNullOrWhiteSpace(emailAddress.Email)) { var emailAddressVm = new EmailAddressViewModel() { CustomerID = customerid.ToString("D"), Email = emailAddress.Email }; return(emailAddressVm); } } } return(null); }
private OutcomeViewModel ConvertPatientInformantDateToUserinfo(EmailAddressViewModel emailAddressModel, OutcomeViewModel model) { model.UserInfo.EmailAddress = emailAddressModel.EmailAddress; return(model); }
public PersonalDetailViewModel() { AddressInformation = new LocationInfoViewModel(); EmailAddress = new EmailAddressViewModel(); }