smart-access
v0.1.12
Published
Smart Access Controller
Downloads
4
Readme
Smart Access
Managing user access list in a smarter way based on smart-mysql-cache.
How To Install :
npm install smart-access
How To Connect:
Fields user , storage , debugging is required.
For Example :
let collection = {
group: {
attributes: [
{name: 'id'},
{name: 'name'}
]
},
action: {
attributes: [
{name: 'id'},
{name: 'name'},
{name: 'order'},
{name: 'caption'}
]
},
access: {
attributes: [
{name: 'id'},
{name: 'group', collection:'group'},
{name: 'action', collection:'action'},
{name: 'status'}
]
},
user: {
attributes: [
{name: 'group', collection:'group'},
{name: 'id'},
{name: 'username'},
{name: 'password'},
{name: 'birthday'},
{name: 'name'},
{name: 'surname'}
]
}
};
var {cache} = require("smart-mysql-cache");
var db = new cache({collection});
var access_list = require("smart-access");
var user = null;
function login(username, password){
let user = db.collection('user').find({username, password});
var access = new access_list(user, db);
}
function granted(name, order){
if(user != null){
return user.granted(name, order);
}
return false;
}
Granted Method :
Check access user by collection name and operation order.
access.granted(collection_name , operation_order)
For Example :
if(access.granted("bus","add")){
console.log("ok");
}
Allow Method:
Allow access user by collection name and operation order
access.allow(collection_name , operation_order);
For Example :
access.allow("bus","remove");
if(access.granted("bus","remove")){
console.log("access granted.");
}
// always log "access granted."
Deny Method :
Deny access user by collection name and operation order
access.deny(collection_name , operation_order);
For Example :
access.deny("bus","remove");
if(access.granted("bus","remove")){
console.log("access granted.");
}
// never log enything