OptimalBits / node_acl

Access control lists for node applications
2.62k stars 371 forks source link

looking for example #167

Open kcnkumar opened 8 years ago

kcnkumar commented 8 years ago

Hi

I am using Node, Express and mongo. can anyone give an example how to use ACL in DEMO App and please explain steps how to use ACL in same...

ThanX..

ghost commented 8 years ago

The same problem...

kcnkumar commented 8 years ago

hey @jaider2523
if you tried anything or if you referring any portals/sites just share the same,let me try the same

Regards Nishanth Skype ID: nishanthrajsh

ghost commented 8 years ago

@kcnkumar

Any solution....?,

kcnkumar commented 8 years ago

i kept that on hold man and this is my try where i can take page to 500/access denied

in model/user.js

User.add({ name: { type: Types.Name, required: true, index: true }, email: { type: Types.Email, initial: true, required: true, index: true }, password: { type: Types.Password, initial: true, required: true } }, 'Permissions', { isAdmin: { type: Boolean, label: 'Can access Keystone', index: true }, role: { type: Types.Select, options: 'superuser, public, guest', initial: true, required: true } });

and in routes/index.js

initialize var mongoose = require('mongoose'); var acl = require('acl'); var dbc = mongoose.createConnection('mongodb://127.0.0.1:27017/my-site', {});

acl.addUserRoles("superuser","user",cb); app.get('/contact', acl.middleware(2, 'fflender', 'read'), routes.views.contact);

here when you switch to contact it shows 500/access denied

if you tried with different please share and if any one else know about #167 please guide us!!!!

Wuntenn commented 8 years ago

A really good example was given by @icompuiz found in the examples right here: https://github.com/OptimalBits/node_acl/issues/38

It definitely helped to understand things quite a bit in terms of the acl side of things whilst making slight customisations to meanjs (which I am more familiar).

It's possible but I'd have to ask to know for sure, that meanjs code is an evolution of code within the above linked issue which predates the addition of the acl within meanjs:

Loading all the acls is done here and examples of useage are:

Both address acl's use of req.userId vs mongo's:req.user._id**. I would recommend both as nice examples of acl use in conjunction with Mongo, Node and Express.

\ There has since been and update which patches these differences, however the last I checked the published version 0.4.9 doesn't include the lines that make the change. To get the version of 0.4.9 with the update you can install from github via: npm install optimalbits/node_acl.