public BaseResponse <UserModel> Execute(AuthenticateUserRequest request)
        {
            var user      = _userRepository.GetUser(request.Username);
            var validator = new AuthenticateUserValidator(request, user);

            if (!validator.IsValid)
            {
                return(new BaseResponse <UserModel>
                {
                    IsSuccess = false,
                    Messages = validator.Messages
                });
            }

            var password = new Password(request.Password, user.PasswordHash, user.PasswordSalt);

            if (!password.Verify())
            {
                return(new BaseResponse <UserModel>
                {
                    IsSuccess = false,
                    Messages = new List <string>
                    {
                        "The username and password combination was incorrect."
                    }
                });
            }

            return(new BaseResponse <UserModel>
            {
                IsSuccess = true,
                Messages = new List <string>(),
                Data = UserModel.MapFromEntity(user)
            });
        }
Ejemplo n.º 2
0
        public AuthenticateUserValidator(AuthenticateUserRequest request, User user)
        {
            if (string.IsNullOrEmpty(request.Username) || string.IsNullOrEmpty(request.Password))
            {
                IsValid = false;
                Messages.Add("Username or password was not provided.");
            }

            if (user == null)
            {
                IsValid = false;
                Messages.Add("The username and password combination was incorrect.");
            }

            if (user != null && !user.IsActive)
            {
                IsValid = false;
                Messages.Add("User is not activated.");
            }
        }