public async Task <BaseModel> ResetPasswordAsync(string email) { var response = new BaseModel(); if (string.IsNullOrWhiteSpace(email)) { response.Errors.Add(ErrorConstants.EmptyEmailField); return(response); } var existingUser = await _userRepository.GetByEmailAsync(email); if (existingUser == null) { response.Errors.Add(ErrorConstants.ImpossibleToFindUser); return(response); } var newPassword = _passwordHelper.GenerateRandomPassword(); var result = await _userRepository.ResetPasswordAsync(existingUser, newPassword); if (!result) { response.Errors.Add(ErrorConstants.ImpossibleToResetPassword); } result = await _emailHelper.SendMessageAsync(email, newPassword, EmailConstants.NewPasswordSubject); if (!result) { response.Errors.Add(ErrorConstants.ImpossibleToSendMessage); } return(response); }
public async Task <BaseModel> ResetPasswordAsync(string email) { var responseModel = new BaseModel(); if (string.IsNullOrWhiteSpace(email)) { responseModel.Errors.Add(Constants.Errors.EmailInvalid); return(responseModel); } var user = await _userRepository.GetUserByEmailAsync(email); if (user == null || user.IsRemoved) { responseModel.Errors.Add(Constants.Errors.UserFailIdentity); return(responseModel); } ; if (!user.LockoutEnd.Equals(null)) { responseModel.Errors.Add(Constants.Errors.UserBloced); return(responseModel); } var token = await _userRepository.GenerateResetPasswordTokenAsync(user); var newTempPassword = _passwordHelper.GenerateRandomPassword(_configuration); string message = $"This is your Temp password {newTempPassword} ! Please change it`s, after succesfull authorization"; await _emailHelper.SendMailAsync(user.Email, _emailConfig.Value.SubjectRecovery, message); var result = await _userRepository.ResetPasswordAsync(user, token, newTempPassword); if (!result) { responseModel.Errors.Add(Constants.Errors.UserRemoved); } return(responseModel); }
public virtual void SendPasswordReminderEmail(string emailAddress) { var notificationHelper = this.emailService; var user = authenticationService.GetUser(emailAddress); notificationHelper.SendEmailWithTemplatePath(emailAddress, string.Empty, "Password Reminder", "C:/temp/template.txt", new { name = user.UserName, newPassword = passwordHelper.GenerateRandomPassword() }); }