2021-11-25 01:25:27 +00:00
|
|
|
var express = require('express');
|
2021-11-25 00:56:04 +00:00
|
|
|
var router = express.Router();
|
2021-11-25 04:05:33 +00:00
|
|
|
const passport = require('passport');
|
2021-11-25 00:56:04 +00:00
|
|
|
const app = require('../app');
|
|
|
|
|
2021-11-25 03:58:49 +00:00
|
|
|
router.get('/login', (req, res, next) => {
|
2021-11-25 04:22:17 +00:00
|
|
|
res.render('accounts/login', { title : "Login", message: req.flash('error') });
|
2021-11-25 03:58:49 +00:00
|
|
|
});
|
2021-11-25 00:56:04 +00:00
|
|
|
|
2021-11-25 04:07:13 +00:00
|
|
|
router.get('/logout', (req, res, next) => {
|
|
|
|
req.logout();
|
|
|
|
res.redirect("/");
|
|
|
|
});
|
|
|
|
|
2021-11-25 03:58:49 +00:00
|
|
|
router.post('/login',
|
2021-11-25 04:05:33 +00:00
|
|
|
passport.authenticate('local', {
|
2021-11-25 04:22:17 +00:00
|
|
|
failureRedirect: '/auth/login',
|
|
|
|
successRedirect: '/',
|
|
|
|
failureFlash: "Invalid email or password.",
|
2021-11-25 03:58:49 +00:00
|
|
|
}),
|
|
|
|
(req, res, next) => {
|
|
|
|
console.log(req.user);
|
2021-11-25 00:56:04 +00:00
|
|
|
});
|
|
|
|
|
2021-11-25 22:41:10 +00:00
|
|
|
|
2021-11-25 01:25:27 +00:00
|
|
|
|
2021-11-25 00:56:04 +00:00
|
|
|
module.exports = router;
|