【问题标题】:mean.io what's the best way to set up an admin user + admin modulemean.io 设置管理员用户 + 管理模块的最佳方式是什么
【发布时间】: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


    【解决方案1】:

    是的,平均包是您想要使用的。安装意味着:

    npm install -g meanio
    

    安装 mean-admin 包:

    mean install mean-admin
    

    为用户创建管理员角色:

    mean user <your_signin_email> -a admin
    

    【讨论】:

    • 在使用普通用户 -a admin 时遇到一些错误
    • /usr/local/lib/node_modules/mean-cli/lib/cli.js:1119 if (err) throw new Error(err); ^ 错误:错误:在 /usr/local/lib/node_modules/mean-cli/lib/cli.js:1119 找不到模块“/Users/JineshJohn/Desktop/SOA/server/config/env/development.js”: 22 在 /usr/local/lib/node_modules/mean-cli/lib/cli.js:111:21 在 /usr/local/lib/node_modules/mean-cli/lib/utils.js:49:14 在 fs。 js:272:14 在 Object.oncomplete (fs.js:108:15)
    • mean-cli 的功能非常依赖于你项目的文件夹结构。当您运行 'mean user -a admin' 时,mean-cli 正在寻找一个要连接的 mongo 数据库(这就是它将您标记为网站管理员的方式)并寻找位于 ' 中的文件的连接字符串/Users/JineshJohn/Desktop/SOA/server/config/env/' 称为'development.js'。当您第一次使用“mean init myApp”安装时,这就是平均配置平均服务器的方式。如果您对文件夹结构进行了很多更改,那么 mean 的许多功能将无法使用。
    【解决方案2】:

    只是让其他人在文档中获得信息... 您可以通过命令添加一个rool.. 平均用户(电子邮件)-管理员

    【讨论】:

      猜你喜欢
      • 2012-12-14
      • 1970-01-01
      • 1970-01-01
      • 2011-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多