2021-01-30 20:33:06 +01:00
|
|
|
const express = require('express');
|
|
|
|
const router = express.Router();
|
2021-01-28 01:30:55 +01:00
|
|
|
const passport = require('../config/passport')
|
|
|
|
|
|
|
|
/* GET home page. */
|
|
|
|
router.get('/login', function (req, res, next) {
|
2021-01-30 20:33:06 +01:00
|
|
|
res.render('login', {user: req.user});
|
2021-01-28 01:30:55 +01:00
|
|
|
});
|
|
|
|
router.post('/login', passport.authenticate('local', { failureRedirect: '/login' }),
|
|
|
|
function (req, res) {
|
2021-01-30 20:33:06 +01:00
|
|
|
if (req.session.returnTo !== undefined && req.session.returnTo !== null){
|
|
|
|
let url = req.session.returnTo;
|
|
|
|
delete req.session.returnTo;
|
|
|
|
res.redirect(url);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res.redirect('/');
|
2021-01-28 01:30:55 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
router.get('/logout',
|
|
|
|
function (req, res) {
|
|
|
|
req.logout();
|
|
|
|
res.redirect('/');
|
|
|
|
});
|
|
|
|
module.exports = router;
|