2013-09-23 51 views
4

我一直在下面连接角色https://github.com/ForbesLindesay/connect-roles 在我的节点JS应用程序的每一件事情是通过未来除了这个 授权这是上面的链接什么记录在Node.js的角色授权使用连接角色

user.can(action) and user.is(action) 

Inside the views of an express application you may use user.can and user.is 

这是equivallent到req.user.can和req.user.is

e.g. 

<% if (user.can('impersonate')) { %> 
    <button id="impersonate">Impersonate</button> 
<% } %> 

我试图使用它,但我因为在我看来(我的HTML页面)感到很困惑我如何可以检查特定角色。我是否必须致电服务部门检查服务器。因为我不能直接在我的app.js文件如果您使用的玉像使用,因为这

var user = require('connect-roles'); 
user.use('access private page', function (req) { 
    if (req.user.role ==== 'moderator') { 
    return true; 
    }}); 
app.get('/private', user.can('access private page'), function (req, res) { 
    res.render('private'); 
}); 

回答

0

它是那么容易,因为:

if userCan('do something') 
    button#special Do Something