如何將ACL節點js角色與來自數據庫MySQL的用戶連接(sequelize)

[英]How can I connect ACL node js roles with users from database MySQL (sequelize)


I have MySQL database created with Sequelize. Now I want to give roles to users from that database with node acl. This is my acl.js file:

我有用Sequelize創建的MySQL數據庫。現在我想通過節點acl為該數據庫的用戶提供角色。這是我的acl.js文件:

var acl = require('acl');
var aclSeq = require('acl-sequelize');
var sequelize = require('../models/index.js');

//acl
acl = new acl(new aclSeq(sequelize.connection, { prefix: 'acl_' })); 

acl.addUserRoles(4, 'admin');

acl.allow('admin', 'ourdogs', 'view')

module.exports = acl;

The problem is that it creates new databases acl_roles and acl_users but I want to connect users from my existing database "user"

問題是它創建了新的數據庫acl_roles和acl_users但我想從我現有的數據庫“user”連接用戶

id, username, email, password_digest, firstName, lastName, image, EmployeeId (columns)
'4', 'admin', 'admin@admin.com', 'a', 'Admin', NULL,    'http://interworldgems.com/client_login/admin/images/login_icon.png', NULL

And after that call this method which will be allowed just for admin

之后調用此方法,只允許管理員使用

  app.get('/ourdogs', acl.middleware(), function(req, res) {
    models.Dog.findAll().then(function(dogs) {
      res.render('ourdogs/ourdogs', { 
        title: 'Our dogs', 
        dogs: dogs 
      });
    })
  });

By running this code ACL creates these databases

通過運行此代碼,ACL將創建這些數據庫

"acl_roles"

“acl_roles”

key, value (columns)
admin, [4]

"acl_users"

“acl_users”

key, value (columns)
4, ["admin"]

I know my code from acl.js is not correct but I don't know how to connect users from my database and then add them roles with acl. I was looking documentation but I couldn't find anything about this.

我知道我的acl.js代碼不正確,但我不知道如何從我的數據庫連接用戶,然后用acl添加他們的角色。我正在查看文檔,但我找不到任何關於此的內容。

Thank you for helping!

感謝您的幫助!

1 个解决方案

#1


0  

ACL doesn't handle authentication. ACL middleware performs a check like the following:

ACL不處理身份驗證。 ACL中間件執行如下檢查:

acl.isAllowed(req.session.userId, '/ourdogs', 'get')

For it to work you must have already populated req.session.userId. It will check for permission to req.method, so you must assign this permission as well.

要使它工作,您必須已經填充了req.session.userId。它將檢查req.method的權限,因此您也必須分配此權限。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2017/01/10/720f3f676d70ea45bf577cecde3ade6a.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com