public async Task <ActionResult> ForgotPassord([FromBody] UserForgotPasswordModel model) { if (!ModelState.IsValid) { return(BadRequest()); } var user = await _accountService.GetUserByEmail(model.Email); if (user == null) { return(Unauthorized(ErrorMessage.INVALIDEMAILORPASSWORD.ToString())); } var token = GenerateForgotPassowrdCodeToken(); try { await _accountService.SaveForgotPasswordCodeToken(user.Email, token); var resetPasswordLink = _appSettings.FrontEndUrl + String.Format(Constants.NotificationMessages.ResetPasswordUrl, token); var userName = String.Format(Constants.NotificationMessages.UserName, user.FirstName, user.LastName); var message = String.Format(Constants.NotificationMessages.ForgotPasswordMessage, userName, _appSettings.FrontEndUrl, resetPasswordLink); await _emailSender.SendEmailAsync(new MailAddress(user.Email, userName), Constants.NotificationMessages.ForgotPasswordSubject, message); var response = new { forgot_password_token = token }; return(Ok(response)); } catch (ArgumentException aex) { _log.Error(aex); return(Unauthorized(aex.Message)); } catch (Exception ex) { _log.Error(ex); return(BadRequest()); } }
public async Task <IActionResult> ForgotPassword(UserForgotPasswordModel forgotPassword) { // validate and sent a reset password if (ModelState.IsValid) { var user = await _accountRepository.GetUserByEmail(forgotPassword.Email); if (user != null) { // sent reset password email to request user email await _accountRepository.GenerateForgotPaswordToken(user); } ModelState.Clear(); forgotPassword.EmailSent = true; } return(View(forgotPassword)); }
public ActionResult ForgotPassword(UserForgotPasswordModel Model, string Action, string ReturnUrl) { switch (Action.ToUpper()) { case "CANCEL": return(RedirectToAction(Epi.Web.MVC.Constants.Constant.INDEX, "Login")); default: break; } if (!ModelState.IsValid) { var allErrors = ModelState.Values.SelectMany(v => v.Errors); List <string> errorMessages = new List <string>(); string msg = ModelState.First().Value.Errors.First().ErrorMessage.ToString(); ModelState.AddModelError("", msg); return(View("ForgotPassword", Model)); } bool success = _isurveyFacade.UpdateUser(new Enter.Common.DTO.UserDTO() { UserName = Model.UserName, Operation = Constant.OperationMode.UpdatePassword }); if (success) { return(RedirectToAction(Epi.Web.MVC.Constants.Constant.INDEX, "Login")); } else { UserForgotPasswordModel model = new UserForgotPasswordModel(); model.UserName = Model.UserName; ModelState.AddModelError("UserName", "You may have entered an email address that does not match our records. Please try again."); return(View("ForgotPassword", model)); } }
public async Task <IActionResult> ForgotPassword(CancellationToken cancellationToken, UserForgotPasswordModel model) { var userAgent = Request.UserAgent(); var command = new UserManagementCommand <UserForgotPasswordModel>(model, User, userAgent); var result = await Mediator.Send(command, cancellationToken).ConfigureAwait(false); return(Ok(result)); }
public async Task <IActionResult> ForgotPassword(CancellationToken cancellationToken, UserForgotPasswordModel model) { var userAgent = Request.UserAgent(); var command = new UserManagementCommand <UserForgotPasswordModel>(model, User, userAgent); var result = await Mediator.Send(command, cancellationToken).ConfigureAwait(false); return(new OkObjectResult(new { Data = result, Status = StatusCodes.Status200OK })); }