【问题标题】:Node.js roles authorization using Connect Roles使用 Connect Roles 的 Node.js 角色授权
【发布时间】:2013-09-28 02:42:42
【问题描述】:

我一直在关注 Connect 角色https://github.com/ForbesLindesay/connect-roles 在我的节点 js 应用程序中进行授权,除了这个 这是上面链接中记录的内容

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

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

相当于 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');
});

【问题讨论】:

    标签: javascript node.js express passport.js


    【解决方案1】:

    如果您使用 Jade,那么简单:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-23
      • 1970-01-01
      • 2016-05-22
      • 2019-12-30
      • 1970-01-01
      • 2012-05-11
      • 1970-01-01
      • 2014-05-08
      相关资源
      最近更新 更多