Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #51 from SpringRoll/bugfix/auth-helper
Browse files Browse the repository at this point in the history
clean up these if-elses so no more double redirects
  • Loading branch information
chipbell4 authored Jan 2, 2019
2 parents 21dc7cf + a997783 commit 363eaaa
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions app/helpers/access.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,26 @@ module.exports = {
isAuthenticated : function(req, res, next)
{
if (req.isAuthenticated())
{
return next();
req.flash('redirect', req.originalUrl);
res.redirect('/login');
}
else {
req.flash('redirect', req.originalUrl);
res.redirect('/login');
}
},

// Access function if user is not logged in
isAnonymous: function(req, res, next)
{
if (!req.isAuthenticated())
{
return next();
res.redirect('/');
}
else {
req.flash('redirect', req.originalUrl);
res.redirect('/');
}
},
// Editor privilege can:
// - create a new project
Expand All @@ -34,11 +43,17 @@ module.exports = {
if (req.isAuthenticated())
{
if (req.user.privilege >= privilege.editor)
{
return next();
res.redirect('/');
}
else {
return res.redirect('/');
}
}
else {
req.flash('redirect', req.originalUrl);
res.redirect('/login');
}
req.flash('redirect', req.originalUrl);
res.redirect('/login');
},
// Admin can:
// - create a new group
Expand All @@ -49,10 +64,16 @@ module.exports = {
if (req.isAuthenticated())
{
if (req.user.privilege >= privilege.admin)
{
return next();
return res.redirect('/');
}
else {
return res.redirect('/');
}
}
req.flash('redirect', req.originalUrl);
res.redirect('/login');
else {
req.flash('redirect', req.originalUrl);
res.redirect('/login');
}
}
};

0 comments on commit 363eaaa

Please sign in to comment.