/
index.js
55 lines (53 loc) · 1.5 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var Promise = require('bluebird')
var nineModule = {
models : require('./models'),
theme : {
directory : "./public",
index : "/nine/modules/index/index"
},
listen : {
"group.update.before" : function( obj, newGroup){
var bus =this
if( newGroup.users ){
if( !newGroup.password ){
return bus.error(406,"use password to update group")
}else{
return bus.fire("group.findOne",{id:newGroup.id,password:newGroup.password}).then(function(res){
if( !res['model.findOne.group']){
return bus.error(406, "password of group not match")
}
})
}
}
}
},
acl :{
roles : {
"loggedIn" : function(req){
console.log("check is user logged in?", req.session.user )
return req.session.user.id !== undefined
},
"hasGroupPassword" : function(req){
if( !req.param('password') ){
return false
}else{
return req.bus.fire('group.findOne',{password:req.param('password')}).then(function( findRes ){
if( !findRes['model.findOne.group'] ){
return Promise.reject('password not match')
}else{
delete req.params['password'] //resolved
}
})
}
}
},
routes : {
"GET /nine/modules/index/index" : [{
role : 'loggedIn',
redirect : '/nine/modules/user/login'
}],
"PUT /group/*" : ['hasGroupPassword']
}
}
}
module.exports = nineModule