private void DeleteUser(Guid entityId)
        {
            _logService.Info("Hard deleting User: {0}", entityId);

            _userWriteRepository.Delete(entityId);

            _logService.Info("Hard deleted User: {0}", entityId);
        }
Пример #2
0
        public async Task <Response> Handle(Request request, CancellationToken cancellationToken)
        {
            var user = await _userReadRepository.GetAsync(request.Id);

            if (user == null)
            {
                return(new Response().AddError("User does not exists"));
            }

            _userWriteRepository.Delete(user);
            await _uow.CommitAsync();

            return(new Response());
        }
        public void UpdateUsername(Guid userId, string verfiyCode, string password)
        {
            var user = _userReadRepository.Get(userId);

            if (!verfiyCode.Equals(user.PendingUsernameCode, StringComparison.InvariantCultureIgnoreCase))
            {
                _logService.Debug("UpdateUsername failed to validate PendingUsernameCode: {0} for userId: {1}", verfiyCode, userId);
                throw new CustomException(ErrorCodes.InvalidUpdateUsernameCode);
            }

            if (!_userDirectoryProvider.AuthenticateUser(userId.ToString(), password))
            {
                _logService.Debug("UpdateUsername failed to autheticate userId: {0}", userId);
                throw new CustomException(ErrorCodes.UserPasswordError);
            }

            var pendingActivationUser = _userReadRepository.Get(user.PendingUsername, false);

            if (pendingActivationUser != null && pendingActivationUser.Status != UserStatuses.PendingDeletion)
            {
                //Delete any user with username = user.PendingUsername - they must be PendingActivation
                if (pendingActivationUser.Status != UserStatuses.PendingActivation)
                {
                    _logService.Error("UpdateUsername error, existing userId ({0}) to pending username ({1}) failed as username already exists and is not in PendingActivation state", userId, user.PendingUsername);
                    throw new CustomException(ErrorCodes.UsernameExistsAndNotInPendingActivationState);
                }
                _userWriteRepository.Delete(pendingActivationUser.EntityId);
                _authenticationRepository.Delete(pendingActivationUser.EntityId);
            }

            _logService.Info("UpdateUsername updating from '{0}' to '{1}'", user.Username, user.PendingUsername);
            _auditRepository.Audit(user, AuditEventTypes.UsernameChanged, user.EntityId);
            user.Username            = user.PendingUsername;
            user.PendingUsername     = null;
            user.PendingUsernameCode = null;
            _userWriteRepository.Save(user);
            _logService.Info("UpdateUsername updated to '{0}'", user.Username);
        }
Пример #4
0
 public async System.Threading.Tasks.Task Remove(RemoveUserCommand command)
 => await _userWriteRepository.Delete(command.Id);