Пример #1
0
        public (string token, User user) Authenticate(AuthenticateDto dto)
        {
            if (!dto.IsValid())
            {
                NotifyValidationError(dto);
                return(string.Empty, null);
            }

            var user = _userRepository.GetByEmail(dto.Email);

            if (user == null)
            {
                NotifyError(DomainError.UserNotFound);
                return(string.Empty, null);
            }

            if (user.Password != dto.Password.Encrypt())
            {
                NotifyError(DomainError.InvalidPassoword);
                return(string.Empty, null);
            }

            var token = _tokenEncoder.Encoder(user);

            return(token, user);
        }
Пример #2
0
        public void UserDto_is_not_valid(AuthenticateDto dto, string message)
        {
            var result = dto.IsValid();

            result.Should().BeFalse();
            dto.ValidationResult.Errors.Should().NotBeNullOrEmpty();
            dto.ValidationResult.Errors.First().ErrorMessage.Should().Be(message);
        }
Пример #3
0
        public void UserDto_is_valid()
        {
            var dto = new AuthenticateDto
            {
                Email    = "*****@*****.**",
                Password = "******",
            };

            var result = dto.IsValid();

            result.Should().BeTrue();

            dto.ValidationResult.Errors.Should().BeNullOrEmpty();
        }