1
0
mirror of https://github.com/Foltik/Shimapan synced 2025-01-06 00:08:25 -05:00

Small auth fixes

This commit is contained in:
Jack 2017-10-21 15:10:55 -04:00
parent aac5caf6a7
commit 5917e75dda
Signed by: foltik
GPG Key ID: 303F88F996E95541
2 changed files with 5 additions and 3 deletions

View File

@ -38,6 +38,7 @@ router.post('/register', function (req, res, next) {
req.session.save(function(err) { req.session.save(function(err) {
if (err) return next(err); if (err) return next(err);
useInvite(req.body.invite, req.body.username); useInvite(req.body.invite, req.body.username);
req.session.username = req.body.username;
res.status(200).json({'message': 'Registered.'}); res.status(200).json({'message': 'Registered.'});
}); });
}); });
@ -55,6 +56,7 @@ router.post('/login', function (req, res, next) {
if (!user) return res.status(401).json({'message': info}); if (!user) return res.status(401).json({'message': info});
req.logIn(user, function(err) { req.logIn(user, function(err) {
if (err) return next(err); if (err) return next(err);
req.session.username = user;
res.status(200).json({'message': 'Logged in.'}); res.status(200).json({'message': 'Logged in.'});
}); });
})(req, res, next); })(req, res, next);

View File

@ -12,10 +12,10 @@ var fs = require('fs');
var path = require('path'); var path = require('path');
var requireLogin = function(req, res, next) { var requireLogin = function(req, res, next) {
if (!req.session.passport.user) if (!req.session || !req.session.passport)
res.redirect('/login'); return res.redirect('/login');
else else
next(); return next();
}; };
module.exports = function(app) { module.exports = function(app) {