Exemplo n.º 1
0
        public async Task <bool> Handle(UserEditPasswordCommand request, CancellationToken cancellationToken)
        {
            var user = await _userRepository.GetByIdAsync(request.Id);

            if (user == null || user.UserPassword != request.OldPassword.ToMd5())
            {
                await _bus.RaiseEvent(new DomainNotification(request.Id.ToString(), "用户不存在或原密码不正确"), cancellationToken);

                return(false);
            }

            user.UserPassword = request.NewPassword.ToMd5();

            await _userRepository.UpdateAsync(user);

            if (await Commit())
            {
                var key = GirvsEntityCacheDefaults <User> .ByIdCacheKey.Create(user.Id.ToString());

                _bus.RaiseEvent(new RemoveCacheEvent(key), cancellationToken);
                _bus.RaiseEvent(new RemoveCacheListEvent(GirvsEntityCacheDefaults <User> .ListCacheKey.Create()),
                                cancellationToken);
            }

            return(true);
        }
Exemplo n.º 2
0
        public async Task UserEditPassword([FromForm] UserEditPasswordViewModel model)
        {
            var currentUserId = EngineContext.Current.ClaimManager.GetUserId();
            var command       =
                new UserEditPasswordCommand(currentUserId.ToHasGuid().Value, model.OldPassword, model.NewPassword);
            await _bus.SendCommand(command);

            if (_notifications.HasNotifications())
            {
                var errorMessage = _notifications.GetNotificationMessage();
                throw new GirvsException(StatusCodes.Status400BadRequest, errorMessage);
            }
        }