public IActionResult RegisterPassword(string email = null, string code = null) { if (email == null) { throw new ApplicationException("Um e-mail deve ser fornecido para efetivação do Cadastro."); } if (code == null) { throw new ApplicationException("Uma senha deve ser fornecido para efetivação do Cadastro."); } var model = new RegisterPasswordViewModel { Email = email, Code = code, }; return(View(model)); }
public async Task <IActionResult> RegisterPassword(RegisterPasswordViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = await _userManager.Users .SingleOrDefaultAsync(x => x.UserName == model.Email); if (user == null) { // Don't reveal that the user does not exist return(RedirectToAction(nameof(Login))); } var result = await _userManager.ResetPasswordAsync(user, model.Code, model.Password); if (result.Succeeded) { user.EmailConfirmed = true; _context.SaveChanges(); var resultLogin = Microsoft.AspNetCore.Identity.SignInResult.Failed; if (resultLogin.Succeeded) { return(RedirectToAction("Index", "Home")); } else { return(RedirectToAction(nameof(Login))); } } AddErrors(result); return(View(model)); }