【发布时间】:2014-06-01 19:24:49
【问题描述】:
我一直使用http://www.mean.io/ 我很难设置管理员用户 + 管理员模块 +(如果需要)管理acl
到目前为止我在做什么:
将此规则添加到models/user.js
role: {
type: String,
required: true,
default: 'authoring'
}
设置一个 init.js 用于注册 用户管理员喜欢:
var userData = { "name" : "User Admin", "email" : "info@mydomain.com", "username" : "admin","role" : "admin","password":"admin"};
var user = new User(userData);
user.provider = 'local';
user.save(function(err) {
if (err) {
console.log(err);
process.exit();
return;
}
console.log(user);
process.exit();
});
设置三个文件夹
- 管理员
- 默认
- 登录
我不信任管理敏感数据 只有客户端
设置 acl
一个简单的 acl 用于服务器和 客户喜欢:
//SERVER
'use strict';
/**
* Generic require login routing middleware
*/
exports.requiresLogin = function(req, res, next) {
if (!req.isAuthenticated()) {
return res.redirect('/signin');
}
next();
};
/**
* Generic require login routing middleware
*/
exports.apiRequiresLogin = function(req, res,next) {
if (!req.isAuthenticated()) {
return res.jsonp(401,{ error:'User is not authorized'});
}
next();
};
// Profile authorization helpers
exports.isOwnerProfile = function(req, res, next) {
if (req.user.role !== 'admin') {
if (req.profile.id !== req.user.id) {
return res.send(401, 'User is not authorized');
}
}
next();
};
// User admin authorization helpers
exports.isAdmin = function(req, res, next) {
if (req.user.role !== 'admin') {
return res.send(401, 'User is not authorized');
}
next();
};
// Article authorization helpers
exports.requireSameAuthor = function(req, res, next) {
if (req.post.user.id !== req.user.id) {
return res.send(401, 'User is not authorized');
}
next();
};
//CLIENT
.factory('Global', function($cookieStore) {
var user = $cookieStore.get('USER');
var _this = this;
_this._data = {
user: user,
_authenticated: !!user,
_isAdmin: (user.role==='admin'),
isAuthenticated: function() {
return this._authenticated;
},
isAdmin: function() {
return this._isAdmin;
},
isActionDisabled:function(post){
if(this.isAdmin()){
return false;
}
return (this.user.id === post.author_id);
}
};
return _this._data;
})
设置管理员用户 + 管理员模块 + acl 的最佳方式是什么?
我在新版本中看到有包 它们对此有用吗?
更新
抱歉,我没有看到文档 http://www.mean.io/#!/docs
【问题讨论】:
标签: node.js angularjs express mean-stack