-
Notifications
You must be signed in to change notification settings - Fork 0
/
route.js
35 lines (30 loc) · 1.2 KB
/
route.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
import router from 'koa-router';
import * as user from './routes/user';
import * as group from './routes/group';
import logger from './lib/log';
import { ldapConfig } from './config';
import * as util from './lib/util';
async function validateUid(ctx, next) {
let uid = ctx.params.uid;
if (uid && uid.match(/[^0-9a-zA-Z]/) === null) {
await next();
} else {
ctx.status = 403;
}
}
let route = router();
let requireOwnerGroup = user.requireGroup(ldapConfig.adminGroup);
let requireOwner = util.authorizeOr(user.requireOwnership, requireOwnerGroup);
route.post('/auth', user.auth);
route.post('/logout', user.requireLogin, user.logout);
route.get('/u/:uid', user.requireLogin, validateUid, user.show);
route.post('/u/:uid', requireOwner, validateUid, user.update);
route.get('/u/:uid/del', requireOwnerGroup, validateUid, user.remove);
route.get('/u', user.requireLogin, user.list);
route.post('/u', requireOwnerGroup, user.add);
route.get('/g/:gid', user.requireLogin, group.show);
route.get('/g/:gid/del', requireOwnerGroup, group.remove);
route.post('/g/:gid', requireOwnerGroup, group.addMember);
route.get('/g', user.requireLogin, group.list);
route.post('/g', requireOwnerGroup, group.add);
export { route };