public async Task <IActionResult> ForgotPassword(ForgotPasswordViewModel model) { var user = await _userManager.FindByEmailAsync(model.Email); if (user == null || !(await _userManager.IsEmailConfirmedAsync(user))) { // Don't reveal that the user does not exist or is not confirmed return(Ok(new ApiResultOutput { Success = true })); } // For more information on how to enable account confirmation and password reset please // visit https://go.microsoft.com/fwlink/?LinkID=532713 // var code = await _userManager.GeneratePasswordResetTokenAsync(user); var callbackUrl = ClientSideUrlHelper.ResetPasswordCallbackLink(user.Id, code); await _emailSender.SendEmailAsync( model.Email, "Reset Password", $"Please reset your password by clicking here: <a href='{callbackUrl}'>link</a>" ); return(Ok(new ApiResultOutput { Success = true })); }
public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (!result.Succeeded) { return(BadRequest(new ApiResultOutput { Success = false, Message = "Registration failed. Please try again" })); } var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = ClientSideUrlHelper.EmailConfirmationLink(user.Id, code); await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl); await _signInManager.SignInAsync(user, isPersistent : false); return(Ok(new ApiResultOutput { Success = true })); }