Esempio n. 1
0
 /// <summary>
 /// This allows the non-logged on user to have his password
 /// reset and emailed to him.
 /// </summary>
 /// <returns></returns>
 public ActionResult ForgotPassword()
 {
     var viewModel = new ForgotPasswordViewModel()
     {
         RequiresQuestionAndAnswer = _membershipService.RequiresQuestionAndAnswer
     };
     return View(viewModel);
 }
Esempio n. 2
0
        public ActionResult ForgotPassword(ForgotPasswordViewModel model)
        {
            // Get the userName by the email address
            string userName = _membershipService.GetUserNameByEmail(model.Email);

            // Get the user by the userName
            MembershipUser user = _membershipService.GetUser(userName);

            // Now reset the password

            string newPassword = _membershipService.RequiresQuestionAndAnswer
                ? user.ResetPassword(model.PasswordAnswer)
                : user.ResetPassword();

            // Email the new pasword to the user
            try
            {
                string body = BuildMessageBody(user.UserName, newPassword, ConfigSettings.SecurityGuardEmailTemplatePath);
                Mail(model.Email, ConfigSettings.SecurityGuardEmailFrom, ConfigSettings.SecurityGuardEmailSubject, body, true);
            }
            catch (Exception)
            {
            }

            return RedirectToAction("ForgotPasswordSuccess");
        }