Exemplo n.º 1
0
        public bool ChangePassWord(ChangePwdInput inpt)
        {
            var user = db.Users.Find(inpt.ID);

            if (user == null)
            {
                throw new UserFriendlyException("用户不存在");
            }
            else
            {
                if (user.PassWord != inpt.oldPwd)
                {
                    throw new UserFriendlyException("原密码不正确");
                }
                else
                {
                    user.PassWord        = inpt.newPwd;
                    db.Entry(user).State = EntityState.Modified;
                    return(db.SaveChanges() > 0);
                }
            }
        }
Exemplo n.º 2
0
        public ResponseInfoModel ChangePwd([FromBody] ChangePwdInput input)
        {
            ResponseInfoModel json = new ResponseInfoModel()
            {
                Success = 1, Result = new object()
            };

            try
            {
                CheckModelState();

                if (!_userService.ChangePassWord(input))
                {
                    json.Success = 0;
                    json.Result  = LocalizationConst.ChangePwdFail;
                }
            }
            catch (Exception e)
            {
                DisposeUserFriendlyException(e, ref json, "api/user/changePwd", LocalizationConst.ChangePwdFail);
            }
            return(json);
        }