public async Task <IActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await userManager.FindByEmailAsync(model.Email); if (user == null && !(await userManager.IsEmailConfirmedAsync(user))) { return(View("ForgotPasswordConfirmation", "Account")); } var code = await userManager.GeneratePasswordResetTokenAsync(user); var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code, email = model.Email }, protocol: HttpContext.Request.Scheme); RegisterConfirmEmail emailService = new RegisterConfirmEmail(); await emailService.SendEmailAsync(model.Email, "Reset password", $"To reset your password, follow the <a href='{callbackUrl}'>link</a>"); return(RedirectToAction("ConfirmEmailContentView", "Account")); } return(View(model)); }
public async Task <IActionResult> Register(RegisterViewModel registerViewModel) { if (ModelState.IsValid) { User user = new User { Email = registerViewModel.Email, UserName = registerViewModel.Email, Surname = registerViewModel.Surname, Name = registerViewModel.Name, Role = "user" }; var result = await userManager.CreateAsync(user, registerViewModel.Password); if (result.Succeeded) { var code = await userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); RegisterConfirmEmail email = new RegisterConfirmEmail(); await email.SendEmailAsync(registerViewModel.Email, "Confirm your account", $"Confirm registration by following the <a href='{callbackUrl}'>link</a>"); return(RedirectToAction("ConfirmEmailContentView", "Account")); } } return(View("Login", "Account")); }