コード例 #1
0
        public async Task <ActionResult> ChangePwd(ChangePwdViewModel c)
        {
            if (ModelState.IsValid)
            {
                User user = await db.Users.FindAsync(c.UserID);

                if (user == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                if (user.Password != c.CurrentPwd)
                {
                    ModelState.AddModelError("", "Current password is incorrect");
                    return(View(c));
                }
                user.Password        = c.Password;
                db.Entry(user).State = EntityState.Modified;
                await db.SaveChangesAsync();

                FormsAuthentication.SignOut();
                TempData["Msg"] = "alert('Your password has been changed successfully! Please sign in again.')";
                return(RedirectToAction("SignIn"));
            }
            return(View());
        }
コード例 #2
0
 public async Task <IActionResult> ChangePassword(ChangePwdViewModel model)
 {
     if (!await _userService.ChangePassword(model, _userId))
     {
         return(NotFound("用户密码错误!"));
     }
     return(NoContent());
 }
コード例 #3
0
ファイル: AccountController.cs プロジェクト: zpf1989/MyFrame
        public JsonResult ChangePwd(ChangePwdViewModel changePwdVM)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { code = OperationResultType.ParamError, message = base.ParseModelStateErrorMessage(ModelState) }));
            }

            //验证码校验
            if (Session.Get <string>(KEY_Session_VerifyCode_ChangePwd) != changePwdVM.VerifyCode)
            {
                return(Json(new { code = OperationResultType.ParamError, message = Msg_ChangPwd + "失败,验证码不正确" }));
            }
            var beginTime = Session.Get <DateTime>(KEY_Session_VerifyCode_ChangePwd_BeginTime);

            if (beginTime.AddMinutes(VerifyCodeExpireTime) < DateTime.Now)
            {
                return(Json(new { code = OperationResultType.ParamError, message = Msg_ChangPwd + "失败,验证码已失效,请重新获取" }));
            }
            //重置验证码session设置
            Session.Set(KEY_Session_VerifyCode_ChangePwd, null);
            Session.Set(KEY_Session_VerifyCode_ChangePwd_BeginTime, null);

            var usrId = HttpContext.Session.GetUserId();

            if (usrId == null)
            {
                RedirectToAction("Login");
            }
            var result = _usrSrv.Find(u => u.Id == usrId);

            if (result.ResultType != OperationResultType.Success)
            {
                return(Json(new { code = OperationResultType.ParamError, message = result.Message }));
            }
            var usrs = result.AppendData as List <User>;

            if (usrs == null || usrs.Count < 1)
            {
                return(Json(new { code = OperationResultType.QueryNull, message = "用户不存在" }));
            }
            if (EncryptionHelper.GetMd5Hash(changePwdVM.OldPassword) != usrs[0].Password)
            {
                return(Json(new { code = OperationResultType.ParamError, message = "旧密码不正确" }));
            }
            if (EncryptionHelper.GetMd5Hash(changePwdVM.NewPassword) == usrs[0].Password)
            {
                return(Json(new { code = OperationResultType.ParamError, message = "新旧密码不能相同" }));
            }
            result = _usrSrv.Update(u => u.Id == (int)usrId, u => new User {
                Password = EncryptionHelper.GetMd5Hash(changePwdVM.NewPassword)
            });
            if (result.ResultType != OperationResultType.Success)
            {
                return(Json(new { code = OperationResultType.Error, message = result.Message }));
            }
            return(Json(new { code = OperationResultType.Success }));
        }
コード例 #4
0
        public async Task <IActionResult> ChangePwdByOldPwd(ChangePwdViewModel viewmodel)
        {
            var result = await _loginService.ChangePassword(User.GetUserName(), viewmodel.OldPassword, viewmodel.NewPassword);

            if (!result)
            {
                return(this.BadRequestResult("密码修改失败,请确认旧密码是否正确!"));
            }
            return(Ok());
        }
コード例 #5
0
        public async Task <IActionResult> ChangePwdByOldPwd(ChangePwdViewModel viewmodel)
        {
            var result = await _loginService.ChangePasswordAsync(User.GetUserName(), viewmodel.OldPassword, viewmodel.NewPassword);

            if (!result)
            {
                return(this.BadRequestResult(AccountConstants.ACCOUNT_MODIFY_PASSWORD_FAIL));
            }
            return(Ok());
        }
コード例 #6
0
        public ActionResult ChangePwdSave(ChangePwdViewModel model)
        {
            var result = _userBus.ChangePwdSave(model);

            if (result.Item1)
            {
                return(RedirectToAction("ChangePwd"));
            }
            else
            {
                ModelState.AddModelError("", result.Item2);
                return(View("ChangePwd", model));
            }
        }
コード例 #7
0
        /// <summary>
        /// 修改用户密码
        /// </summary>
        /// <param name="model"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task <bool> ChangePassword(ChangePwdViewModel model, Guid userId)
        {
            var oldPwd = Md5Helper.Md5Encrypt(model.OldPassword);
            var user   = await _userRepository.GetAll().FirstOrDefaultAsync(m => m.Id == userId && m.Password == oldPwd);

            if (user == null)
            {
                return(false);
            }
            var newPwd = Md5Helper.Md5Encrypt(model.NewPassword);

            user.Password = newPwd;
            await _userRepository.EditAsync(user);

            return(true);
        }
コード例 #8
0
        public ActionResult Changepwd(ChangePwdViewModel changPwd)
        {
            Response _response = new Response();
            Response _comparePwd;

            if (!ModelState.IsValid)
            {
                _response.Status  = 0;
                _response.Message = General.GetModelErrorString(ModelState);
                return(Json(_response));
            }
            else
            {
                _comparePwd = _customerServiceManager.Verify(Session["username"].ToString(), Security.SHA256(changPwd.Oldpwd));

                if (_comparePwd.Status == 0)
                {
                    _response.Status  = 0;
                    _response.Message = "原始密码不正确";
                    return(Json(_response));
                }
                else
                {
                    int _custId;
                    if (!int.TryParse(Session["AdminAccountId"].ToString(), out _custId))
                    {
                        _response.Status  = 0;
                        _response.Message = "ID有问题!";
                        return(Json(_response));
                    }
                    else
                    {
                        _response = _customerServiceManager.ChangePassword(_custId, Security.SHA256(changPwd.Newpwd));
                        if (_response.Status == 1)
                        {
                            _response.Message = "恭喜您,密码修改成功!";
                            Session.Clear();
                            _response.Url = Url.Action("Login", "Account");
                        }
                    }
                }
            }
            return(Json(_response));
        }
コード例 #9
0
        public Tuple <bool, string> ChangePwdSave(ChangePwdViewModel sourceModel)
        {
            var userid = LZY.Code.OperatorProvider.Provider.GetCurrent().UserId;

            if (sourceModel == null)
            {
                return(Tuple.Create(false, "错误的请求对象!"));
            }


            var oldModel = FindModel(userid);

            if (sourceModel.OldPwd != oldModel.p_password)
            {
                return(Tuple.Create(false, "原密码错误!"));
            }
            oldModel.p_password = sourceModel.NewPwd;
            return(SaveModel(oldModel));
        }
コード例 #10
0
        public IActionResult ChangePwd(ChangePwdViewModel model)
        {
            if (!this.TryValidateModel(model))
            {
                return(this.Json("0002", this.ModelErrorMessage));
            }

            var api = this.userService.ChangePassword(new ChangePwdReqs()
            {
                UserId      = this.GetAppUser().UserId,
                Password    = model.Password,
                OriginalPwd = model.Original,
            });

            if (api.Status != ApiStatus.Success)
            {
                return(this.Json("0002", api.Status == ApiStatus.Fail ? api.Message : "修改密码错误"));
            }

            return(this.Json("0000", "修改成功"));
        }
コード例 #11
0
        public ActionResult Changepwd(ChangePwdViewModel cpvm)
        {
            Response _resp = new Response();

            if (!ModelState.IsValid)
            {
                _resp.Status  = 0;
                _resp.Message = General.GetModelErrorString(ModelState);
                return(Json(_resp));
            }
            string _passowrd = Security.SHA256(cpvm.Oldpwd);

            _resp = _adminaccountmanager.Verify(Session["username"].ToString(), _passowrd);
            if (_resp.Status == 0)
            {
                _resp.Message = "原始密码不正确";
                return(Json(_resp));
            }
            int _adminid;

            if (!int.TryParse(Session["AdminAccountId"].ToString(), out _adminid))
            {
                _resp.Status  = 0;
                _resp.Message = "错误!参数不正确";
                return(Json(_resp));
            }
            else
            {
                _resp = _adminaccountmanager.ChangePassword(_adminid, Security.SHA256(cpvm.Newpwd));
            }
            if (_resp.Status == 1)
            {
                _resp.Message = "恭喜!修改密码成功!";
                Session.Clear();
                _resp.Url = Url.Action("login", "adminaccount", new { area = "admin" });
            }
            return(Json(_resp));
        }