Exemplo n.º 1
0
        public ActionResult ForgotPassword(ForgotPasswordViewModel model)
        {
            // Get the userName by the email address
            string userName = Membership.GetUserNameByEmail(model.Email);
            if (String.IsNullOrEmpty(userName))
            {
                ModelState.AddModelError("", ErrorCodeToString(AccountCreateStatus.InvalidUserName));
                return View(model);
            }

            // Get the user by the userName
            MembershipUser user = Membership.GetUser(userName);
            if (user == null)
            {
                ModelState.AddModelError("", ErrorCodeToString(AccountCreateStatus.InvalidUserName));
                return View(model);
            }
            else if (!user.IsApproved)
            {
                ModelState.AddModelError("", ErrorCodeToString(AccountCreateStatus.UserNotYetApproved));
                return View(model);
            }
            else if (user.IsLockedOut)
            {
                ModelState.AddModelError("", ErrorCodeToString(AccountCreateStatus.UserAccountLocked));
                return View(model);
            }
            else
            {
                if (ModelState.IsValid)
                {
                    RegisterPasswordSuccessModel rpsModel = new RegisterPasswordSuccessModel();
                    rpsModel = ResetPassword(userName, model.PasswordAnswer, GetLoginUrl());

                    if (rpsModel.RegisterPasswordSuccess)
                    {
                        return RedirectToAction("ForgotPasswordSuccess", new { userName = userName });
                    }
                    else
                    {
                        ModelState.AddModelError("", rpsModel.ErrorMessage);
                        return View(model);
                    }
                }
            }

            return View(model);
        }
Exemplo n.º 2
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 = Membership.RequiresQuestionAndAnswer
     };
     return View(viewModel);
 }