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

var express = require('express');
var router = express.Router();
const passport = require('passport');
const accounts = require('./../database/accounts/accounts');
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');
}
}
router.get('/login', (req, res, next) => {
res.render('accounts/login', { title : "Login", message: req.flash('error') });
});
router.get('/logout', (req, res, next) => {
req.logout();
res.redirect("/");
});
router.post('/login',
passport.authenticate('local', {
failureRedirect: '/auth/login',
successRedirect: '/',
failureFlash: "Invalid email or password.",
}),
(req, res, next) => {
console.log(req.user);
});
module.exports = router;