text: const express = require('express');
  const { check, body } = require('express-validator');
  
  const authController = require('../controllers/auth');
  const User = require('../models/user');
  
  const router = express.Router();
  
  router.get('/login', authController.getLogin);
  
  router.post(
      '/login',
      [
          body('email')
              .isEmail()
              .withMessage('Please enter a valid email.')
              .normalizeEmail(),
          body('password', 'Please enter a password with only numbers and leters and at least 5 charactors')
              .isLength({min: 5})
              .isAlphanumeric()
              .trim()
      ],
      authController.postLogin
  );
  
  router.post('/logout', authController.postLogout);
  
  router.get('/signup', authController.getSignup);
  
  router.post(
      '/signup',
      [
          check('email')
              .isEmail()
              .withMessage('Please enter a valid email.')
              .custom((value, {req}) => {
                  return User.findOne({email: value})
                      .then(existUser => {
                          if (existUser) {
                              return Promise.reject('Email already exist!');
                          }
                      });
              })
              .normalizeEmail(),
          body('password', 'Please enter a password with only numbers and leters and at least 5 charactors')
              .isLength({min: 5})
              .isAlphanumeric()
              .trim(),
          body('confirmPassword').custom((value, { req }) => {
              if (value !== req.body.password) {
                  throw new Error('Passwords have to match!');
              }
              return true;
          })
      ],
      authController.postSignup
  );
  
  router.get('/reset', authController.getReset);
  
  router.post('/reset', authController.postReset);
  
  router.get('/reset/:token', authController.getNewPassword);
  
  router.post('/new-password', authController.postNewPassword);
  
  module.exports = router;