Last active
August 29, 2015 13:57
-
-
Save digitalsadhu/9398307 to your computer and use it in GitHub Desktop.
Idea for new interface for admittance js
This file contains 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 fs = require('fs') | |
, admittance = require('admittance') | |
//read from the text file where we store pairs of user ids and permissions | |
var storeR = fs.createReadStream(__dirname + '/my-store.txt') | |
//read in permissions | |
storeR.pipe(admittance) | |
//do a permissions check | |
if (admittance(userid).is('admin')) { | |
//yay, user is admin! | |
} |
This file contains 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 fs = require('fs') | |
, admittance = require('admittance') | |
//read from the text file where we store pairs of user ids and permissions | |
var storeR = fs.createReadStream(__dirname + '/my-store.txt') | |
//write to the text file where we store pairs of user ids and permissions | |
var storeW = fs.createReadStream(__dirname + '/my-store.txt') | |
//read in permissions | |
storeR.pipe(admittance) | |
//create a permission and store it | |
admittance(userid, 'admin').pipe(storeW) | |
//define a tree permission structure | |
admittance('editor', 'admin') //admin can do anything an editor can | |
.admittance('subscriber', 'editor') //editor can do anything a subscriber can | |
.admittance('user', 'editor') //editor can also do anything a user can | |
.pipe(storeW) //persist the structure | |
//do a permissions check | |
if (admittance(userid).is('admin')) { | |
//yay, user is admin! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment