JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 18
  • Score
    100M100P100Q24970F
  • License ISC

Smart Access Controller

Package Exports

  • smart-access

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (smart-access) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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