#62 Fixed 401s

master
Keith Irwin 2017-04-20 22:31:10 -04:00
parent 6dfcf09ab2
commit 3f2da8abfc
No known key found for this signature in database
GPG Key ID: 378933C743E2BBC0
5 changed files with 18 additions and 9 deletions

View File

@ -30,7 +30,11 @@ module.exports = {
// Ensure administrator
ensureAdmin: (req,res,next)=>{
if (req.user.isAdmin){ return next(); }
else { res.sendStatus(401); }
else {
let err = new Error("Unauthorized");
err.status = 401;
next(err);
}
//TODO: test this by logging in as !isAdmin and go to /admin
}

View File

@ -119,6 +119,7 @@ module.exports = (passport)=>{
// No googleId either
else {
// console.log(`Couldn't find ${service} user.`);
req.session.flashType = 'warning';
req.session.flashMessage = `There's no user for that ${service} account. `;
return done();

View File

@ -22,9 +22,14 @@ module.exports = (app, passport) => {
req.session.flashMessage = undefined;
res.redirect( req.session.next || '/map' );
},
appLoginCallback = (req,res)=>{
appLoginCallback = (req,res,next)=>{
console.log('appLoginCallback called.');
if (req.user){ res.send(req.user); }
else { res.sendStatus(401); }
else {
let err = new Error("Unauthorized");
err.status = 401;
next(err);
}
};
// Login/-out

View File

@ -16,9 +16,8 @@ router.get('/:slug?', (req,res,next)=>{
User.findOne({slug:req.params.slug})
.then( (mapuser)=>{
if (mapuser===undefined){
res.sendStatus(404);
} else {
if (!mapuser){ next(); } //404
else {
res.render('map', {
mapuser: mapuser,
mapApi: env.googleMapsAPI,

View File

@ -117,9 +117,9 @@ const
app.use( '/test', require('./config/routes/test.js' ) );
}
app.get('/500', (req,res)=>{
Balls
});
// app.get('/500', (req,res)=>{
// Balls
// });
}