Beispiel #1
0
        public ActionResult ChangePassword_Post(ChangePasswordModel model)
        {
            if (!User.Identity.IsAuthenticated)
                return Redirect("/");

            //if all fields are empty, just go back.

            if (String.IsNullOrEmpty(model.OldPassword) ||
                String.IsNullOrEmpty(model.NewPassword) ||
                String.IsNullOrEmpty(model.NewPasswordRepeat))
            {
                return RedirectToAction("ChangePassword",
                    new { userMessage = "Please input the old password and the new passwod, twice." });
            }

            if (model.NewPassword != model.NewPasswordRepeat)
            {
                return RedirectToAction("ChangePassword",
                    new { userMessage = "Please input the old password and the new passwod, twice." });
            }

            if (model.OldPassword == model.NewPasswordRepeat)
            {
                return RedirectToAction("ChangePassword",
                    new { userMessage = "Please input the old password and the new passwod, twice." });
            }

            try
            {
                MembershipUser u = Membership.GetUser(User.Identity.Name);
                if (u.ChangePassword(model.OldPassword, model.NewPassword))
                {

                }
                else
                {
                    return RedirectToAction("ChangePassword",
                        new { userMessage = "Could not change password. Please try again or contact an administrator." });
                }
            }
            catch (Exception ex)
            {
                //todo: logging

                return RedirectToAction("ChangePassword",
                    new { userMessage = "Could not change password. Please try again or contact an administrator." });
            }

            return RedirectToAction("Index");
        }
Beispiel #2
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (!User.Identity.IsAuthenticated)
                return Redirect("/");

            return View(model);
        }