const express = require('express');
const { body } = require('express-validator');
const authController = require('../controllers/auth.controller');
const { redirectIfAuthenticated, requireAuth } = require('../middleware/auth');

const router = express.Router();

router.get('/login', redirectIfAuthenticated, authController.showLogin);
router.post('/login', redirectIfAuthenticated, [body('email').isEmail(), body('password').notEmpty()], authController.login);
router.post('/logout', requireAuth, authController.logout);
router.get('/change-password', requireAuth, authController.showChangePassword);
router.post('/change-password', requireAuth, authController.changePassword);

module.exports = router;
