Last active
          March 18, 2021 22:24 
        
      - 
      
- 
        Save tiagolpadua/ea6013dae6f8bc567ebe70a5feae399f to your computer and use it in GitHub Desktop. 
    cmail-back-master\src\controllers\LoginController.js
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import HttpStatus from 'http-status' | |
| import * as requestUtils from '../infra/utils/requestUtils' | |
| import * as LoginInputDto from './dto/input/LoginInputDto' | |
| import * as tokenManager from '../infra/tokenManager' | |
| export class LoginController { | |
| constructor(usersService) { | |
| this.usersService = usersService | |
| } | |
| signIn = (req, res) => { | |
| if (req.validations.hasErrors()) { | |
| requestUtils.errorResponse(res, req.validations.errors) | |
| return; | |
| } | |
| const userLoginInfo = LoginInputDto.extractLoginInfo(req.body) | |
| this.usersService.login(userLoginInfo) | |
| .then((loginResponse) => { | |
| requestUtils.defaultResponse(res, loginResponse, HttpStatus.CREATED) | |
| }) | |
| .catch((err) => { | |
| requestUtils.errorResponse(res, err) | |
| }) | |
| } | |
| // Método novo | |
| validate = (req, res) => { | |
| const senderToken = req.headers.authorization; | |
| tokenManager.verify(senderToken) | |
| .then(() => requestUtils.defaultResponse(res)) | |
| .catch(() => requestUtils.defaultResponse(res, null, 401)); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment