This repository has been archived on 2024-04-05. You can view files and clone it, but cannot push or open issues/pull-requests.
score-tracker/routes/auth.js

39 lines
957 B
JavaScript
Raw Normal View History

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 01:25:27 +00:00
const accounts = require('./../database/accounts/accounts');
2021-11-25 00:56:04 +00:00
const app = require('../app');
function adminLoggedIn(req, res, next) {
if (req.user && req.user[2]) {
next();
}
else {
req.flash('error', 'An admin account is required to access this page.');
res.redirect('/auth/login');
}
}
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 01:25:27 +00:00
2021-11-25 00:56:04 +00:00
module.exports = router;