Example #1
0
        public CommandResponse <User> GetUserWriteNoResult(string username)
        {
            var user = _userRepository.GetUser(username);

            if (user is null)
            {
                CommandResponse <User> .FromFailure("USER.NOT.FOUND", user);
            }

            return(CommandResponse <User> .FromSuccess(user));
        }
Example #2
0
        public async Task <CommandResponse <User> > Authenticate(string username, string password)
        {
            var user = (await _mediator.Send(GetUserByQuery.New(x => x.Username == username))).FirstOrDefault();

            if (user is null || !PasswordHelper.VerifyPasswordHash(password, user.PasswordHash, user.PasswordSalt))
            {
                return(CommandResponse <User> .FromFailure(AuthentificationServiceException.AuthentificationFailed));
            }

            return(CommandResponse <User> .FromSuccess(user));
        }
Example #3
0
        public async Task <CommandResponse <UserView> > Handle(FindUserByUsernameCommand request, CancellationToken cancellationToken)
        {
            var query = new GetUserByQuery(x => x.Username == request.Username);

            var user = (await _mediator.Send(query)).FirstOrDefault();

            if (user is null)
            {
                return(CommandResponse <UserView> .FromFailure(FindUserByUsernameCommandException.UserNotFound));
            }

            var userView = UserView.FromUser(user);

            return(CommandResponse <UserView> .FromSuccess(userView));
        }
Example #4
0
        public async Task <CommandResponse <UserView> > Handle(RegisterUserCommand request, CancellationToken cancellationToken)
        {
            var user = new User(request.Username);

            var isUsernameAlreadyExists = (await _mediator.Send(new GetUserByQuery(x => x.Username == user.Username))).Any();

            if (isUsernameAlreadyExists)
            {
                return(CommandResponse <UserView> .FromFailure(RegisterUserCommandException.UsernameAlreadyExists));
            }

            var userCreated = await _mediator.Send(new RegisterUserQuery(user, request.Password));

            var userView = UserView.FromUser(userCreated);

            return(CommandResponse <UserView> .FromSuccess(userView));
        }