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

25 lines
693 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');
2021-11-25 03:58:49 +00:00
router.get('/login', (req, res, next) => {
res.render('accounts/login', { title : "Login" });
});
2021-11-25 00:56:04 +00:00
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 03:58:49 +00:00
failureRedirect: '/fail',
successRedirect: '/success',
}),
(req, res, next) => {
console.log(req.user);
2021-11-25 00:56:04 +00:00
});
2021-11-25 01:25:27 +00:00
router.post('/register', (req, res, next) => {
accounts.createUser(req.body.email, req.body.password)
.then(res.redirect('/'));
});
2021-11-25 00:56:04 +00:00
module.exports = router;