1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/backend/routes/UserRouter.ts

78 lines
2.1 KiB
TypeScript
Raw Normal View History

2016-03-19 04:36:58 +08:00
///<reference path="../../typings/main.d.ts"/>
import {UserMWs} from "../middlewares/UserMWs";
import {UserRoles} from "../../common/entities/User";
import {AuthenticationMWs} from "../middlewares/AuthenticationMWs";
import {UserRequestConstrainsMWs} from "../middlewares/UserRequestConstrainsMWs";
2016-03-19 04:36:58 +08:00
export class UserRouter{
constructor(private app){
this.addLogin();
this.addChangePassword();
this.addCreateUser();
this.addDeleteUser();
this.addListUsers();
this.addChangeRole();
2016-03-19 04:36:58 +08:00
}
private addLogin() {
this.app.post("/api/user/login",
AuthenticationMWs.inverseAuthenticate,
AuthenticationMWs.login,
AuthenticationMWs.renderUser
);
};
private addChangePassword() {
2016-03-20 17:49:49 +08:00
this.app.post("/api/user/:id/password",
AuthenticationMWs.authenticate,
UserRequestConstrainsMWs.forceSelfRequest,
UserMWs.changePassword,
UserMWs.renderOK
);
};
private addCreateUser() {
this.app.put("/api/user",
AuthenticationMWs.authenticate,
AuthenticationMWs.authorise(UserRoles.Admin),
UserMWs.createUser,
UserMWs.renderOK
2016-03-19 04:36:58 +08:00
);
};
private addDeleteUser() {
this.app.delete("/api/user/:id",
AuthenticationMWs.authenticate,
AuthenticationMWs.authorise(UserRoles.Admin),
UserRequestConstrainsMWs.notSelfRequest,
UserMWs.deleteUser,
UserMWs.renderOK
);
};
private addListUsers() {
this.app.post("/api/user/list",
AuthenticationMWs.authenticate,
AuthenticationMWs.authorise(UserRoles.Admin),
UserMWs.listUsers
);
};
private addChangeRole() {
2016-03-20 17:49:49 +08:00
this.app.post("/api/user/:id/role",
AuthenticationMWs.authenticate,
AuthenticationMWs.authorise(UserRoles.Admin),
UserRequestConstrainsMWs.notSelfRequestOr2Admins,
UserMWs.changeRole,
UserMWs.renderOK
);
};
2016-03-19 04:36:58 +08:00
}