public IActionResult EditEmail(EditEmailViewModel model) { if (!ModelState.IsValid) { ViewData["doOverride"] = true; return(View(model)); } if (userManager.FindByEmailAsync(model.New).GetAwaiter().GetResult() != null) { ViewData["doOverride"] = true; // TODO: A better error message? ModelState.AddModelError("legend_Email", "That email address is already in use in this service."); return(View(model)); } var login = User.Identity.Name; var user = userManager.FindByEmailAsync(login).GetAwaiter().GetResult(); user.Email = model.New; user.UserName = model.New; userManager.UpdateAsync(user).GetAwaiter().GetResult(); signInManager.SignOutAsync().GetAwaiter().GetResult(); return(RedirectToAction("Index", "Home")); }
public IActionResult EditEmail() { var login = User.Identity.Name; var user = userManager.FindByEmailAsync(login).GetAwaiter().GetResult(); var model = new EditEmailViewModel { Current = user.Email }; return(View(model)); }
// // GET: /Account/EditEmail public async Task <ActionResult> EditEmail() { User user = await _userService.GetAsync(Utility.Helpers.IdentityHelpers.GetUserId(this.HttpContext.User.Identity)); EditEmailViewModel model = new EditEmailViewModel() { CurrentEmailAddress = user.EmailAddress }; return(View(model)); }
// // GET: /Account/EditEmail public ActionResult EditEmail() { var user = _userService.Get(IdentityHelpers.GetUserId(User.Identity)); var model = new EditEmailViewModel() { CurrentEmailAddress = user.Email }; return(View(model)); }
public async Task <IActionResult> EditEmail(string employeeId) { Employee employee = await _userManager.FindByIdAsync(employeeId); EditEmailViewModel model = new EditEmailViewModel { EmployeeId = employee.Id, EmailAddress = employee.Email }; return(View(model)); }
public IActionResult DoEditEmail(EditEmailViewModel viewModel, MobileModel mobileModel) { var isEmailExisting = _sysUserService.Queryable().Any(x => x.Email == viewModel.NewEmail && x.IsDeleted == false); if (isEmailExisting) { if (mobileModel.IsMobile) { return(new JsonResult(new { code = EnumResponseStatus.WARNING, name = "new-email", error_message_key = CPLConstant.MobileAppConstant.EditEmailScreenExistingEmail })); } return(new JsonResult(new { success = false, name = "new-email", message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "ExistingEmail") })); } var user = _sysUserService.Queryable().FirstOrDefault(x => x.Id == HttpContext.Session.GetObjectFromJson <SysUserViewModel>("CurrentUser").Id&& x.IsDeleted == false); if (user != null) { user.Email = viewModel.NewEmail; HttpContext.Session.SetObjectAsJson("CurrentUser", Mapper.Map <SysUserViewModel>(user)); _sysUserService.Update(user); _unitOfWork.SaveChanges(); if (mobileModel.IsMobile) { return(new JsonResult(new { code = EnumResponseStatus.SUCCESS, success_message_key = CPLConstant.MobileAppConstant.EditEmailScreenEmailUpdatedSuccessfully })); } return(new JsonResult(new { success = true, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "EmailUpdated") })); } if (mobileModel.IsMobile) { return(new JsonResult(new { code = EnumResponseStatus.WARNING, error_message_key = CPLConstant.MobileAppConstant.EditEmailScreenNonExistingAccount })); } return(new JsonResult(new { success = false, message = LangDetailHelper.Get(HttpContext.Session.GetInt32("LangId").Value, "NonExistingAccount") })); }
public async Task <ActionResult> EditEmail(EditEmailViewModel model) { if (ModelState.IsValid) { var user = _userService.Get(IdentityHelpers.GetUserId(User.Identity)); if (_userService.IsPasswordMatchForUser(user.UserID, model.Password)) { String originalEmail = user.Email; //Check if the new email address is already assosciated with another account if (_userService.GetByEmail(model.NewEmailAddress) != null) { _userService.SetEmailAddress(user.UserID, model.NewEmailAddress); _uow.Save(); //Send notification email String subject = "Account Email Changed"; String body = "This email is to inform you that the email address associated with your account has been changed."; var message = new MailMessage("*****@*****.**", originalEmail, subject, body); await _emailService.SendMessageAsync(message); ViewBag.SuccessMessage = "Your email address has been changed."; ModelState.Clear(); return(View()); } ModelState.AddPropertyError <EditEmailViewModel>(m => m.NewEmailAddress, "An account with this email already exists."); } else { ModelState.AddPropertyError <EditEmailViewModel>(m => m.Password, "Invalid password."); return(View(model)); } } //We got this far, some.panel .panel-default failed return(View(model)); }
public async Task <IActionResult> EditEmail(EditEmailViewModel model) { if (!ModelState.IsValid) { return(View()); } Employee employee = await _userManager.FindByIdAsync(model.EmployeeId); string token = await _userManager.GenerateChangeEmailTokenAsync(employee, model.NewEmailAddress); string tokenLink = Url.Action("ConfirmEmailChange", "Account", new { userId = model.EmployeeId, newEmail = model.NewEmailAddress, token }, Request.Scheme); string subject = "Email Change Request Confirmation"; string body = $"<h1>Hello { employee.FullName } </h1> \n\n" + $"<p>You've recently requested for an email change from { employee.Email } to { model.NewEmailAddress }</p> \n\n" + "<p>Please click below to confirm</p> \n\n" + $"<a href='{ tokenLink }'><button style='color:#fff; background-color:#007bff; border-color:#007bff;'>Confirm</button></a> \n\n" + "<p>If the link doesn't work, you can copy and paste the below URL</p> \n\n" + $"<p> { tokenLink } </p> \n\n\n" + "<p>Thank you!</p>"; try { MimeMessage message = _emailSender.GenerateContent(employee.FullName, employee.Email, subject, body); _emailSender.SendEmail(message); } catch (Exception e) { _logger.LogError(e.Message); ModelState.AddModelError(string.Empty, "Something went wrong. Please contact the Admin"); return(View()); } return(RedirectToAction(nameof(ViewEmployee), new { employeeId = model.EmployeeId })); }
public async Task <ActionResult> EditEmail(EditEmailViewModel model) { if (ModelState.IsValid) { User user = await _userService.GetAsync(Utility.Helpers.IdentityHelpers.GetUserId(this.HttpContext.User.Identity)); if (_userService.VerifyPassword(user, model.Password)) { user.EmailAddress = model.NewEmailAddress; ServiceOperationResult result = await _userService.UpdateAsync(user); if (result.Succeeded) { _uow.Commit(); await _userService.SendEmailAsync(user, EmailHelpers.UserEmails.AccountPropertyChanged("Email Address")); TempData.Add(KeyTempDataAccountUpdates, new List <String>() { "Your email address has been changed." }); return(RedirectToAction("Index")); } else { ModelState.MergeErrors(result.Errors); } } else { ModelState.AddErrorForProperty <EditEmailViewModel>(m => m.Password, "Invalid password."); } } //We got this far, something failed return(View(model)); }
protected override void OnAppearing() { base.OnAppearing(); BindingContext = new EditEmailViewModel(); }
public async Task OnGetAsync(Guid id) { var emailDto = await _emailAppService.GetAsync(id); Email = ObjectMapper.Map <EmailDto, EditEmailViewModel>(emailDto); }