public JsonResult GeneratePasswordResetLink(PasswordResetLink passwordResetLink) { UserSettings userSettings = UserService.GetUserByEmailAddress(passwordResetLink.Email); if (userSettings == null) { PostRequestResult result = new PostRequestResult { Success = false, ErrorMessage = "A user with the specified email address could not be found" }; return(Json(result)); } else { bool success = UserService.SendResetPasswordLink(passwordResetLink.Email); PostRequestResult result = new PostRequestResult { Success = success, ErrorMessage = success ? "" : "Couldn't send email because of an unexpected error" }; return(Json(result)); } }
private bool SendResetPasswordLink(PasswordResetLink passwordResetLink) { string emailSubject = "Project Jetson Password Reset"; string emailBody = GetEmailBody(passwordResetLink); return(_emailService.SendEmail(passwordResetLink.Email, emailSubject, emailBody)); }
private string GetEmailBody(PasswordResetLink passwordResetLink) { string emailBody = RazorEngineWrapper.RunCompile("Views/User", "PasswordResetEmailBodyTemplate.cshtml", passwordResetLink); return(emailBody); }
public IActionResult GeneratePasswordResetLink(string id) { try { User user = UserService.GetUser(id); PasswordResetLink link = AuthService.GeneratePasswordResetLink(user); return(Ok(link)); } catch (EntityNotFoundException exception) { return(HandleResourceNotFoundException(exception)); } catch (Exception exception) { return(HandleUnexpectedException(exception)); } }
public bool SendResetPasswordLink(string email) { string token = GeneratePasswordResetToken(); string url = "http://" + _hostname + "/User/PasswordReset?id=" + token; DatabaseUser user = _dbQueryService.GetUserByEmailAddress(email); if (user == null) { return(false); } PasswordResetLink passwordResetLink = new PasswordResetLink(url, email, user.FirstName + " " + user.LastName); if (SendResetPasswordLink(passwordResetLink)) { return(_dbQueryService.PersistPasswordResetToken(token, email)); } else { return(false); } }