Exemplo n.º 1
0
        public async Task <LoginAccessDTO> Login(LoginDTO credentials)
        {
            if (!credentials.IsValid())
            {
                _notificationContext.AddNotifications(credentials.ValidationResult);
                return(null);
            }
            else
            {
                var user = await _userRepository.GetByLogin(credentials.Login);

                if (user != null && Authenticate(user.PasswordDigest, credentials.Password))
                {
                    return(TokenObject(_mapper.Map <UserDTO>(user)));
                }
                else
                {
                    return(new LoginAccessDTO
                    {
                        Authenticated = false,
                        AccessToken = null
                    });
                }
            }
        }