Created
September 27, 2014 05:09
-
-
Save dhigginbotham/b639d1c1df9a333c02a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var roles = { | |
optin: 1, | |
user: 3, | |
admin: 10 | |
}; | |
function canPlayRoleOf(user, role) { | |
if (roles.hasOwnProperty(role)) { | |
return (user.role >= roles[role] ? true : false); | |
} else { | |
return null; | |
} | |
} | |
function roleMiddleware(req, res, next) { | |
if (req.user) { | |
req.canPlayRoleOf = canPlayRoleOf; | |
} | |
next(); | |
} | |
module.exports = roleMiddleware; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment