mirror of
https://github.com/mclueppers/xo-server.git
synced 2025-07-27 16:04:49 +02:00
Permission checking in user.create().
This commit is contained in:
parent
93bb0e9097
commit
d80ff58bb8
16
src/api.js
16
src/api.js
@ -220,7 +220,21 @@ Api.fn.user = {
|
|||||||
throw Api.err.INVALID_PARAMS;
|
throw Api.err.INVALID_PARAMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.users.create(p_email, p_pass, p_perm).then(function (user) {
|
var user_id = session.get('user_id');
|
||||||
|
if (undefined === user_id)
|
||||||
|
{
|
||||||
|
throw Api.err.UNAUTHORIZED;
|
||||||
|
}
|
||||||
|
|
||||||
|
var users = this.users;
|
||||||
|
return users.get(user_id).then(function (user) {
|
||||||
|
if (!user.hasPermission('admin'))
|
||||||
|
{
|
||||||
|
throw Api.err.UNAUTHORIZED;
|
||||||
|
}
|
||||||
|
|
||||||
|
return users.create(p_email, p_pass, p_perm);
|
||||||
|
}).then(function (user) {
|
||||||
return (''+ user.get('id'));
|
return (''+ user.get('id'));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -162,6 +162,7 @@ function Xo()
|
|||||||
this.users.add({
|
this.users.add({
|
||||||
'email': 'bob@gmail.com',
|
'email': 'bob@gmail.com',
|
||||||
'pw_hash': '$2a$10$PsSOXflmnNMEOd0I5ohJQ.cLty0R29koYydD0FBKO9Rb7.jvCelZq',
|
'pw_hash': '$2a$10$PsSOXflmnNMEOd0I5ohJQ.cLty0R29koYydD0FBKO9Rb7.jvCelZq',
|
||||||
|
'permission': 'admin',
|
||||||
}).done();
|
}).done();
|
||||||
|
|
||||||
// This events are used to automatically close connections if the
|
// This events are used to automatically close connections if the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user