public async Task <IActionResult> ForgotUserPassword([FromBody] ForgotPasswordRequestModel model) { try { var user = await _userManager.FindByEmailAsync(model.Email); var token = await _userManager.GeneratePasswordResetTokenAsync(user); byte[] tokenBytes = Encoding.UTF8.GetBytes(token); var tokenEncoded = WebEncoders.Base64UrlEncode(tokenBytes); var clientAddress = Configuration.GetSection("ApplicationSettings").GetValue <string>("ClientAddress"); var passwordResetLink = $"{clientAddress}/user/reset-password?email={user.Email}&token={tokenEncoded}"; var newEmail = new Email() { To = user.Email, Subject = "reset password", Body = $"Reset password here: {passwordResetLink}" }; SendMail.Execute(newEmail); return(Ok(new { message = $"A link to reset your password has been sent to your email address: {maskEmail(user.Email)}" })); } catch (Exception ex) { return(BadRequest(ex.Message)); } }