mean.io什么是设置管理员用户+管理模块的最佳方式

时间:2014-04-17 13:32:26

标签: node.js angularjs express mean-stack

我一直使用http://www.mean.io/ 我有设置管理员用户+管理模块的麻烦 +(如果需要)管理acl

到目前为止我做了什么:

添加此规则tomodels / 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

服务器和for的简单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

2 个答案:

答案 0 :(得分:5)

是的,平均套餐是您想要使用的。要安装卑鄙:

npm install -g meanio

安装mean-admin软件包:

mean install mean-admin

为用户创建管理员角色:

mean user <your_signin_email> -a admin

答案 1 :(得分:0)

其他人在文档中有信息...... 您可以通过命令添加滚动.. 卑鄙用户(电子邮件)-a admin