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

96 lines
2.6 KiB
TypeScript
Raw Normal View History

2016-05-26 02:17:42 +08:00
import {UserMWs} from "../middlewares/user/UserMWs";
import {UserRoles} from "../../common/entities/User";
2016-05-26 02:17:42 +08:00
import {AuthenticationMWs} from "../middlewares/user/AuthenticationMWs";
import {UserRequestConstrainsMWs} from "../middlewares/user/UserRequestConstrainsMWs";
2016-05-09 23:04:56 +08:00
import {RenderingMWs} from "../middlewares/RenderingMWs";
2016-05-09 23:04:56 +08:00
export class UserRouter {
constructor(private app) {
this.addLogin();
2016-05-17 05:15:03 +08:00
this.addLogout();
this.addGetSessionUser();
this.addChangePassword();
2016-05-09 23:04:56 +08:00
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,
RenderingMWs.renderSessionUser
);
};
2016-05-17 05:15:03 +08:00
private addLogout() {
this.app.post("/api/user/logout",
AuthenticationMWs.authenticate,
AuthenticationMWs.logout,
RenderingMWs.renderOK
);
};
private addGetSessionUser() {
this.app.get("/api/user/login",
AuthenticationMWs.authenticate,
RenderingMWs.renderSessionUser
);
};
private addChangePassword() {
2016-03-20 17:49:49 +08:00
this.app.post("/api/user/:id/password",
AuthenticationMWs.authenticate,
UserRequestConstrainsMWs.forceSelfRequest,
UserMWs.changePassword,
RenderingMWs.renderOK
);
};
private addCreateUser() {
this.app.put("/api/user",
AuthenticationMWs.authenticate,
AuthenticationMWs.authorise(UserRoles.Admin),
UserMWs.createUser,
RenderingMWs.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,
RenderingMWs.renderOK
);
};
private addListUsers() {
this.app.get("/api/user/list",
AuthenticationMWs.authenticate,
AuthenticationMWs.authorise(UserRoles.Admin),
UserMWs.listUsers,
RenderingMWs.renderResult
);
};
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,
RenderingMWs.renderOK
);
};
2016-03-19 04:36:58 +08:00
}