Exemplo n.º 1
0
        public ActionResult ChangePassword(ProfileChangePassword model)
        {
            model.Trim();
            var result = new QsResult {
                Success = false
            };

            if (!ModelState.IsValid)
            {
                return(Json(result));
            }
            var user = _userService.GetUserById(GetUserInCookie().UserId);

            if (!user.Password.Equals(Utilities.MD5(model.CurrentPassword)))
            {//验证原始密码
                result.Message = @"原始密码输入错误";
                ModelState.AddModelError("CurrentPassword", result.Message);
                return(Json(result));
            }
            if (model.CurrentPassword.Equals(model.NewPassword))
            {//判断到新旧密码一致
                result.Message = @"新旧密码一致,未进行修改操作";
                return(Json(result));
            }
            user.Password = Utilities.MD5(model.NewPassword);
            _userService.UpdateUserInformation(user);
            SafeOutAuthCookie();
            result.Success = true;
            return(Json(result));
        }
Exemplo n.º 2
0
        public ActionResult ChangePassword(ProfileChangePassword form)
        {
            var user = Auth.User;

            if (user == null)
            {
                return(HttpNotFound());
            }

            if (ModelState.IsValid)
            {
                // ChangePassword will throw an exception rather than return false in certain failure scenarios.
                bool changePasswordSucceeded;
                try
                {
                    changePasswordSucceeded = WebSecurity.ChangePassword(User.Identity.Name, form.OldPassword, form.NewPassword);
                }
                catch (Exception ex)
                {
                    changePasswordSucceeded = false;
                    ModelState.AddModelError("password1", ex.Message);
                }

                if (changePasswordSucceeded)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("password2", "The current password is incorrect or the new password is invalid.");
                }
            }

            return(View("Index", new ProfileEdit {
                Name = user.Name, Email = user.Email, Username = user.Username
            }));
        }
Exemplo n.º 3
0
        public ActionResult _ChangePassword()
        {
            var model = new ProfileChangePassword();

            return(PartialView(model));
        }