Ejemplo n.º 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);
        }