public IActionResult Authenticate(UserRequestAuthenticateViewModel user)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                return(Ok(service.Authenticate(user)));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        public UserResponseAuthenticateViewModel Authenticate(UserRequestAuthenticateViewModel user)
        {
            User _user = repository.GetByEmailAndPassword(user.Email, UtilsService.EncryptPassword(user.Password));

            if (_user == null)
            {
                throw new ApiException("Email/Password not found", HttpStatusCode.NotFound);
            }

            if (!_user.IsAuthorised)
            {
                throw new ApiException("Your account is not activate yet.", HttpStatusCode.NotFound);
            }

            string token = tokenService.GenerateToken(mapper.Map <ContextUserViewModel>(_user));

            UserResponseAuthenticateViewModel _userResponse = mapper.Map <UserResponseAuthenticateViewModel>(_user);

            _userResponse.Token = token;

            return(_userResponse);
        }