public ActionResult Index(ChangeEmailInputModel model) { if (ModelState.IsValid) { } return View(); }
public async Task <IActionResult> ChangeEmail(ChangeEmailInputModel model) { var user = await _userManager.GetUserAsync(User); if (user == default) { return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.")); } var vm = new ChangeEmailViewModel(model, user.EmailConfirmed); if (!ModelState.IsValid) { return(View("Index", vm)); } if (string.Equals(model.Email, model.NewEmail, StringComparison.InvariantCultureIgnoreCase)) { ViewData["StatusMessage"] = "L'indirizzo inserito e' uguale al precedente!"; return(View("Index", vm)); } var code = await _userManager.GenerateChangeEmailTokenAsync(user, model.NewEmail); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl = Url.Action( "ChangeEmailConfirmation", "ChangeEmail", new { userId = user.Id, email = model.NewEmail, code }, Request.Scheme); var message = new EmailMessage { Sender = new() { Email = _options.Name, Name = _options.Address }, Subject = "Confermi la modifica della Email?", Body = $"Ciao {user}, <br /> Per confermare il cambio di email <a href='{HtmlEncoder.Default.Encode(callbackUrl ?? string.Empty)}'>clicca qui!</a>.", To = new[] { new MailAddress { Name = user.Name, Email = model.NewEmail } } }; await _email.SendAsync(message); ViewData["StatusMessage"] = "Ti abbiamo inviato una mail di conferma. Controlla la tua casella di posta elettronica."; return(View("Index", vm)); }
public async Task <IdentityResult> UpdateEmail([FromBody] ChangeEmailInputModel request) { if (!this.ModelState.IsValid) { throw new InvalidOperationException(); } var user = await _userManager.FindByNameAsync(request.CurrentEmail); var result = await _userManager.ChangeEmailAsync(user, request.NewEmail, request.Token); if (result.Succeeded) { await _userManager.SetUserNameAsync(user, request.NewEmail); } return(result); }
public async Task <ActionResult> ChangeEmail(ChangeEmailInputModel inputModel) { try { var confirmEmailIdentityResult = await this.userService.ChangeEmail( inputModel.ChangeEmailToken, inputModel.NewEmail, this.GetUserId(this.User)); if (confirmEmailIdentityResult.Succeeded) { return(this.Ok()); } return(this.BadRequest(confirmEmailIdentityResult.Errors)); } catch (Exception ex) { this.loggerService.LogException(ex); return(this.BadRequest()); } }