问题描述
所有的时候,我使用
我有麻烦建立一个管理员用户+管理模块
+(如果需要)管理ACL
All the times I use http://www.mean.io/I've got the hassle to set up an admin user + admin module+ (if needs) manage acl
我做的到现在:
添加此规则tomodels / user.js的
role: {
type: String,
required: true,
default: 'authoring'
}
成立一个init.js为报名参加
admin用户,如:
var userData = { "name" : "User Admin", "email" : "[email protected]", "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();
});
设置了三个文件夹
- 管理
- 默认
- 登录
我不相信明智的管理数据
只有客户端
I don't trust manage sensible dataonly client side
设置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中的最佳方式?
What's the best way to set up a admin user + admin module + acl ?
我在新REALIZE看到有包
他们是很有用的这个?
I saw in the new realise there are packagescan them be usefull for this ?
对不起,我没有看到该文档
Sorry I didn't see the dochttp://www.mean.io/#!/docs
推荐答案
是平均包你会想用什么。要安装意思是:
Yes the mean packages are what you will want to use. To install mean:
npm install -g meanio
要安装的均管理软件包:
To install the mean-admin package:
mean install mean-admin
要创建用户管理员角色:
To create admin role for user:
mean user <your_signin_email> -a admin
这篇关于mean.io什么是设立一个管理员用户+管理模块的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!