Example #1
0
        public async Task <IActionResult> OnPostAsync([FromBody] ModifyPasswordDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(await Task.FromResult(new JsonResult(new
                {
                    Status = false,
                    ErrorMessage = ModelState.Where(e => e.Value.Errors.Count > 0).Select(e => e.Value.Errors.First().ErrorMessage).First()
                })));
            }

            var userId = _accountContext.UserId;

            var command = new ModifyPasswordCommand(userId, dto.Password, dto.NewPassword);
            await _bus.SendCommand(command);

            if (_notifications.HasNotifications())
            {
                var errorMessage = string.Join(";", _notifications.GetNotifications().Select(x => x.Content));
                return(await Task.FromResult(new JsonResult(new
                {
                    status = false,
                    errorMessage
                })));
            }

            return(await Task.FromResult(new JsonResult(new
            {
                status = true
            })));
        }
Example #2
0
        public async Task <(int code, string msg)> ModifyPasswordAsync(ModifyPasswordDto dto)
        {
            // ignore some params check...

            var userInfo = await _repo.GetUserInfoByUserNameAsync(dto.UserName);

            if (userInfo == null)
            {
                return(2001, "can not find user");
            }

            userInfo.ModifyPassword(dto.Password);

            var isStrongPassword = userInfo.CheckIsStrongPassword();

            if (!isStrongPassword)
            {
                return(1001, "password is too weak");
            }

            var isSucc = await _repo.ModifyUserAsync(userInfo);

            if (isSucc)
            {
                _logger.LogInformation($"modify password of {dto.UserName} succeed..");
                return(0, "ok");
            }
            else
            {
                _logger.LogWarning($"modify password of {dto.UserName} fail..");
                return(9000, "error");
            }
        }
Example #3
0
        public object ModifyPassword(ModifyPasswordDto modifyPasswordDto)
        {
            Worker worker = _ctx.Worker.SingleOrDefault(w => w.Id == modifyPasswordDto.Id && w.Password.Equals(modifyPasswordDto.Password));
            var    result = new object();

            if (worker != null)
            {
                worker.Password = modifyPasswordDto.NewPassword;
                _ctx.SaveChanges();
                result = new
                {
                    isSuccess = true,
                    message   = "修改密码成功!"
                };
            }
            else
            {
                result = new
                {
                    isSuccess = false,
                    message   = "修改密码失败!"
                }
            };
            return(result);
        }
Example #4
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="dto">密码修改数据传输对象</param>
        public void ModifyPasswordDto(ModifyPasswordDto dto)
        {
            var user = _userRepository.Get(LsSession.UserId.Value);

            if (!user.CheckPassword(dto.OldPassword))
            {
                throw new LsException("原密码输入不正确");
            }
            user.ModifyPassword(dto.NewPassword);
            _userRepository.Update(user);
        }
Example #5
0
        public async Task ModifyPassword_Should_Return_2001_When_User_Is_Not_Exist()
        {
            A.CallTo(() => _repo.GetUserInfoByUserNameAsync(A <string> ._)).Returns(Task.FromResult <CoreLayer.Domains.UserInfo>(null));

            var dto = new ModifyPasswordDto {
                UserName = "******", Password = "******"
            };

            var(code, msg) = await _biz.ModifyPasswordAsync(dto);

            code.ShouldBe(2001);
            msg.ShouldBe("can not find user");
        }
Example #6
0
        public async Task ModifyPassword_Should_Return_9000_When_Modify_Failed()
        {
            A.CallTo(() => _repo.GetUserInfoByUserNameAsync(A <string> ._)).Returns(Task.FromResult(new CoreLayer.Domains.UserInfo {
                IsDel = false
            }));
            A.CallTo(() => _repo.ModifyUserAsync(A <CoreLayer.Domains.UserInfo> ._)).Returns(Task.FromResult(false));

            var dto = new ModifyPasswordDto {
                UserName = "******", Password = "******"
            };

            var(code, msg) = await _biz.ModifyPasswordAsync(dto);

            code.ShouldBe(9000);
            msg.ShouldBe("error");
        }
Example #7
0
        public async Task ModifyPassword_Should_Return_1001_When_Password_Is_Weak()
        {
            A.CallTo(() => _repo.GetUserInfoByUserNameAsync(A <string> ._)).Returns(Task.FromResult(new CoreLayer.Domains.UserInfo {
                IsDel = false
            }));


            var dto = new ModifyPasswordDto {
                UserName = "******", Password = "******"
            };

            var(code, msg) = await _biz.ModifyPasswordAsync(dto);

            code.ShouldBe(1001);
            msg.ShouldBe("password is too weak");
        }
Example #8
0
        public JsonResponse ModifyPassword([FromBody] ModifyPasswordDto dto)
        {
            //判断用户是否登录
            if (!TokenHelper.CheckLoginStateByUserId(dto.UserId))
            {
                return(BadResponse("用户未登录", null, false));
            }
            if (dto.UserId == null || dto.OldPassword == null || dto.NewPassword == null || dto.Verify == null || dto.VerifyId == null)
            {
                return(BadResponse("参数提供不完整"));
            }
            //判断验证码是否输入正确
            if (!TokenHelper.CheckVerify(dto.VerifyId, dto.Verify))
            {
                return(BadResponse("验证码错误"));
            }
            UserInfo model = new UserInfo();

            model = UserInfoBll.GetModelById(dto.UserId);

            //判断用户是否存在
            if (model == null)
            {
                return(BadResponse("用户不存在"));
            }
            //新密码加密
            dto.NewPassword = PasswordHelper.PwdStrToHashStr(dto.NewPassword);
            //判断新旧密码是否相同
            if (dto.NewPassword == model.Password)
            {
                return(BadResponse("旧密码与新密码相同"));
            }
            //若不相同新密码写入数据库
            model.Password = dto.NewPassword;
            if (!UserInfoBll.Update(model))
            {
                return(BadResponse("网络错误,请重试"));
            }
            return(OkResponse(null, "密码修改成功"));
        }
Example #9
0
        public async Task <IActionResult> OnPostAsync([FromBody] ModifyPasswordDto dto)
        {
            var userId = _accountContext.UserId;

            var command = new ModifyPasswordCommand(userId, dto.Password, dto.NewPassword);
            await _bus.SendCommand(command);

            if (_notifications.HasNotifications())
            {
                var errorMessage = string.Join(";", _notifications.GetNotifications().Select(x => x.Content));
                return(await Task.FromResult(new JsonResult(new
                {
                    status = false,
                    errorMessage
                })));
            }

            return(await Task.FromResult(new JsonResult(new
            {
                status = true
            })));
        }
Example #10
0
 public ActionResult ConfirmModifyPassword(ModifyPasswordDto dto)
 {
     _userService.ModifyPasswordDto(dto);
     return(ResultSuccess <string>("修改成功!"));
 }
 public object ModifyPassword(ModifyPasswordDto modifyPasswordDto)
 {
     return(_userManager.ModifyPassword(modifyPasswordDto));
 }
Example #12
0
 public object ModifyPassword([FromBody] ModifyPasswordDto modifyPasswordDto)
 {
     return(_userAppService.ModifyPassword(modifyPasswordDto));
 }