public async Task <IActionResult> ResetPasswordRequest([FromBody, BindRequired] PasswordResetRequestData data) { // Find user attached to email or username. var emailOrUsername = data.EmailOrUsername.ToLowerInvariant(); var user = (await _userRepo.GetAllUsers()).SingleOrDefault(u => u.Email.ToLowerInvariant().Equals(emailOrUsername) || u.Username.ToLowerInvariant().Equals(emailOrUsername)); if (user is null) { return(NotFound(emailOrUsername)); } // Create password reset. var resetRequest = await _passwordResetService.CreatePasswordReset(user.Email); // Create email. var message = new MimeMessage(); message.To.Add(new MailboxAddress(user.Name, user.Email)); message.Subject = "Combine password reset"; message.Body = new TextPart("plain") { Text = string.Format("A password reset has been requested for the user {0}. Follow the link to reset " + "{0}'s password. {1}/forgot/reset/{2} \n\n If you did not request a password reset please " + "ignore this email", user.Username, data.Domain, resetRequest.Token) }; if (await _emailService.SendEmail(message)) { return(Ok()); } return(StatusCode(StatusCodes.Status500InternalServerError)); }
public static RequestPasswordResetCommand NewCommand(PasswordResetRequestData data) { return(new RequestPasswordResetCommand( data.Email == null ? null : ValidEmail.Parse(data.Email), data.Username == null ? null : ValidUsername.Parse(data.Username))); }