Reputation: 32766
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
What I do up to now:
add this rule tomodels/user.js
role: {
type: String,
required: true,
default: 'authoring'
}
set up an init.js for sign up the user admin like:
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();
});
set up three folders
I don't trust manage sensible data only client side
set up acl
a simple acl both for the server and for the client like:
//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;
})
What's the best way to set up a admin user + admin module + acl ?
I saw in the new realise there are packages can them be usefull for this ?
Sorry I didn't see the doc http://www.mean.io/#!/docs
Upvotes: 3
Views: 9661
Reputation: 617
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
Upvotes: 5
Reputation: 294
Just so others have the info in the docs... You can add a rool through the command.. mean user (email) -a admin
Upvotes: 0