Exemple #1
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="input"></param>
        /// <param name="modelState"></param>
        /// <returns></returns>
        public async Task <bool> ChangePasswordAsync(int userId, UserChangePasswordInput input, ModelStateDictionary modelState)
        {
            //判断当前密码是否输入正确
            var chkUser = await _userService.GetNormalUserAsync(userId, input.CurrentPassword);

            if (chkUser == null)
            {
                modelState.AddModelError("CurrentPassword", "当前密码不正确");
                return(false);
            }

            return(await _userService.ChangePasswordAsync(chkUser.UserId, input.NewPassword, modelState));
        }
        public object ChangePasswordSave(UserAddress userAddress, UserChangePasswordInput userInput)
        {
            //TODO: (erikpo) Check permissions

            ModelResult results = faUserService.ChangePassword(userAddress, userInput);

            if (!results.IsValid)
            {
                ModelState.AddModelErrors(results.ValidationState);

                return(ChangePassword(userAddress));
            }

            return(Redirect(Url.AppPath(Url.ManageUsers())));
        }
Exemple #3
0
        public async Task <ApiResult> ChangePassword(UserChangePasswordInput input)
        {
            var result = new ApiResult();

            if (!await _adminUserService.ChangePasswordAsync(HttpContext.User.GetUserId(), input, ModelState))
            {
                result.Code    = 400;
                result.Message = $"修改密码失败: {ModelState.FirstErrorMessage()}";
            }
            else
            {
                result.Code    = 200;
                result.Message = "修改密码成功";
            }

            return(result);
        }
Exemple #4
0
        public ModelResult ChangePassword(User user, UserChangePasswordInput userInput)
        {
            ValidationStateDictionary validationState = new ValidationStateDictionary();

            validationState.Add(typeof(UserChangePasswordInput), validator.Validate(userInput));

            if (!validationState.IsValid)
            {
                return(new ModelResult(validationState));
            }

            string passwordSalt = Guid.NewGuid().ToString("N");
            string password     = userInput.Password.SaltAndHash(passwordSalt);

            repository.SetModuleData(user, "FormsAuthentication", string.Format("{0}|{1}", passwordSalt, password));

            pluginEngine.ExecuteAll("UserChangePassword", new { user, context });

            return(new ModelResult());
        }
        public async Task<IResponseOutput> ChangePasswordAsync(UserChangePasswordInput input)
        {
            if (input.ConfirmPassword != input.NewPassword)
            {
                return ResponseOutput.NotOk("新密码和确认密码不一致!");
            }

            var entity = await _userRepository.GetAsync(input.Id);
            var oldPassword = MD5Encrypt.Encrypt32(input.OldPassword);
            if (oldPassword != entity.Password)
            {
                return ResponseOutput.NotOk("旧密码不正确!");
            }

            input.Password = MD5Encrypt.Encrypt32(input.NewPassword);

            entity = _mapper.Map(input, entity);
            var result = (await _userRepository.UpdateAsync(entity)) > 0;

            return ResponseOutput.Result(result);
        }
        public async Task <ApiResult> ChanagePassword(UserChangePasswordInput input)
        {
            var returnResult = new ApiResult();
            var userId       = HttpContext.User.GetUserId();
            var user         = await _userService.GetNormalUserAsync(userId, input.CurrentPassword);

            if (user == null)
            {
                returnResult.Code    = 400;
                returnResult.Message = "当前密码输入错误,请重试。";
                return(returnResult);
            }
            if (!await _userService.ChangePasswordAsync(HttpContext.User.GetUserId(), input.NewPassword, ModelState))
            {
                returnResult.Code    = 400;
                returnResult.Message = ModelState.FirstErrorMessage();
                return(returnResult);
            }

            returnResult.Code    = 200;
            returnResult.Message = "修改密码成功";
            return(returnResult);
        }
Exemple #7
0
        public async Task <ApiResult> ChangePassword([FromBody] UserChangePasswordInput input)
        {
            var result = new ApiResult();

            if (!int.TryParse(HttpContext.User.Identity.Name, out var value))
            {
                result.Code    = 400;
                result.Message = "修改资料失败: 获取用户信息失败";
            }

            if (!await _adminUserService.ChangePasswordAsync(HttpContext.User.GetUserId(), input, ModelState))
            {
                result.Code    = 400;
                result.Message = "修改密码失败" + ModelState.FirstErrorMessage();
            }
            else
            {
                result.Code    = 200;
                result.Message = "修改密码成功";
            }

            return(result);
        }
Exemple #8
0
 public async Task <IResponseOutput> ChangePassword(UserChangePasswordInput input)
 {
     return(await _userServices.ChangePasswordAsync(input));
 }
Exemple #9
0
 public async Task <IResponseOutput> ChangePasswordAsync(UserChangePasswordInput input)
 {
     return(ResponseOutput.Ok());
 }
 public void ChangePassword(UserAddress userAddress, UserChangePasswordInput userInput, out ValidationStateDictionary validationState)
 {
     throw new NotImplementedException();
 }
Exemple #11
0
 public async Task <IResultModel> ChangePassword(UserChangePasswordInput input)
 {
     return(await _userServices.ChangePasswordAsync(input));
 }