Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 路由相关
const Router = require('koa-router')
// 日志相关
const log = require('tracer').colorConsole({ level: require('config').get('log').level })
// 初始化路由
const router = new Router()
// 认证相关
const passport = require(__dirname + '/passport_config.js')
// 角色权限
let acl = require('acl')
acl = new acl(new acl.memoryBackend())
acl.allow('admin', 'xbatis', 'remove')
/**
* 认证登录
*/
router.post('/xauth/login', function (ctx, next) {
return passport.authenticate('local', function (err, user, info, status) {
if (user) {
ctx.body = 'Y'
acl.addUserRoles(user.id, 'admin')// 添加用户与其角色,这里模拟使用admin
return ctx.login(user)
} else {
ctx.body = info
}
})(ctx, next)
})
resource.acl.forEach(access => {
var aclString: Array = this.aclStringFromMask(access["accessmask"]);
acl.allow(access["role"], resource["name"], aclString, function (err, res) {
if (res) {
console.log("User joed is allowed to view blogs")
}
if (err) {
//console.log("error in acl " + err);
}
})
});
acl.addUserRoles(req.user['id'], ['admin', documentEditorRole], function(err) {
if (err) {
res.write('Error: User ' + req.user['id'] + ' not added as admin');
res.end();
}
else {
acl.allow(['admin', documentEditorRole], newDocumentId, 'update');
res.write('Success: User ' + req.user['id'] + ' added as admin');
res.end();
}
});
}
mongodbUtils.getDatabase(function(err, database) {
if (database) {
acl = new acl(new acl.mongodbBackend(database, "acl"));
acl.allow(['admin','user'], 'persons', 'view');
callback(null, acl);
}
else {
callback('Error: Cannot access ACL database', null);
}
});