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;
|