コード例 #1
0
        public virtual ActionResult ChangePassword(DriverPasswordFormStub model)
        {
            driver driver = RepoDriver.FindByPk(model.Id);

            if (ModelState.IsValid)
            {
                bool changePasswordSucceeded;

                try
                {
                    MembershipUser currentUser = System.Web.Security.Membership.GetUser(driver.username);
                    changePasswordSucceeded = currentUser.ChangePassword(currentUser.ResetPassword(), model.NewPassword);
                }
                catch (Exception)
                {
                    changePasswordSucceeded = false;
                }

                if (changePasswordSucceeded)
                {
                    string template = HttpContext.GetGlobalResourceObject("MyGlobalMessage", "ChangePassword").ToString();
                    this.SetMessage(template);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
                }
            }

            ViewBag.Username = driver.username;

            return(View("ChangePasswordForm"));
        }
コード例 #2
0
        public virtual ActionResult ChangePassword(Guid id)
        {
            DriverPasswordFormStub viewModel = new DriverPasswordFormStub();
            driver driver = RepoDriver.FindByPk(id);

            ViewBag.Username = driver.username;

            return(View("ChangePasswordForm", viewModel));
        }