text: const router = require('express').Router()
  const userCtrl = require('../controllers/userCtrl')
  const auth = require('../middleware/auth')
  const authAdmin = require('../middleware/authAdmin')
  let User = require('../models/userModel');
  
  router.post('/register', userCtrl.register)
  
  router.post('/activation', userCtrl.activateEmail)
  
  router.post('/login', userCtrl.login)
  
  router.post('/refresh_token', userCtrl.getAccessToken)
  
  router.post('/forgot', userCtrl.forgotPassword)
  
  router.post('/reset', auth, userCtrl.resetPassword)
  
  router.get('/infor', auth, userCtrl.getUserInfor)
  
  router.get('/all_infor', auth, authAdmin, userCtrl.getUsersAllInfor)
  
  router.get('/logout', userCtrl.logout)
  
  router.patch('/update', auth, userCtrl.updateUser)
  
  router.patch('/update_role/:id', auth, authAdmin, userCtrl.updateUsersRole)
  
  router.delete('/delete/:id', auth, authAdmin, userCtrl.deleteUser)
  
  
  
  router.route('/').get((req, res) => {
      User.find()
        .then(users => res.json(users))
        .catch(err => res.status(400).json('Error: ' + err));
    });
    
    router.route('/add').post((req, res) => {
      const name = req.body.name;
      const password = req.body.password;
      const email = req.body.email;
      const role = req.body.role;
    
      const newUser = new User({
          name,
          password,
          email,
          role
        });
    
      newUser.save()
        .then(() => res.json('User added!'))
        .catch(err => res.status(400).json('Error: ' + err));
    });
    
    router.route('/:id').get((req, res) => {
        User.findById(req.params.id)
          .then(user => res.json(user))
          .catch(err => res.status(400).json('Error: ' + err));
      });
      
      router.route('/:id').delete((req, res) => {
        User.findByIdAndDelete(req.params.id)
          .then(() => res.json('User deleted.'))
          .catch(err => res.status(400).json('Error: ' + err));
      });
      
      router.route('/update_r/:id').post((req, res) => {
        User.findById(req.params.id)
          .then(user => {
            user.requirefirstname = req.body.firstname;
            user.lastname = req.body.lastname;
            user.username = req.body.username;
            user.password = req.body.password;
            user.email = req.body.email;
            user.role = req.body.role;
      
            user.save()
              .then(() => res.json('User updated!'))
              .catch(err => res.status(400).json('Error: ' + err));
          })
          .catch(err => res.status(400).json('Error: ' + err));
      });
  
  
  // Social Login
  router.post('/google_login', userCtrl.googleLogin)
  
  router.post('/facebook_login', userCtrl.facebookLogin)
  
  
  module.exports = router