#62 Fixed 401s
parent
6dfcf09ab2
commit
3f2da8abfc
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue