2016-05-25 20:17:42 +02:00
|
|
|
import {UserMWs} from "../middlewares/user/UserMWs";
|
2016-12-27 16:09:47 +01:00
|
|
|
import {UserRoles} from "../../common/entities/UserDTO";
|
2016-05-25 20:17:42 +02:00
|
|
|
import {AuthenticationMWs} from "../middlewares/user/AuthenticationMWs";
|
|
|
|
import {UserRequestConstrainsMWs} from "../middlewares/user/UserRequestConstrainsMWs";
|
2016-05-09 17:04:56 +02:00
|
|
|
import {RenderingMWs} from "../middlewares/RenderingMWs";
|
2016-03-19 17:31:42 +01:00
|
|
|
|
2016-05-09 17:04:56 +02:00
|
|
|
export class UserRouter {
|
|
|
|
constructor(private app) {
|
2016-03-19 17:31:42 +01:00
|
|
|
this.addLogin();
|
2016-05-16 23:15:03 +02:00
|
|
|
this.addLogout();
|
2016-03-20 20:06:14 +01:00
|
|
|
this.addGetSessionUser();
|
2016-03-19 17:31:42 +01:00
|
|
|
this.addChangePassword();
|
2016-05-09 17:04:56 +02:00
|
|
|
|
|
|
|
|
2016-03-19 17:31:42 +01:00
|
|
|
this.addCreateUser();
|
|
|
|
this.addDeleteUser();
|
|
|
|
this.addListUsers();
|
|
|
|
this.addChangeRole();
|
2016-03-18 21:36:58 +01:00
|
|
|
}
|
|
|
|
|
2016-03-19 17:31:42 +01:00
|
|
|
private addLogin() {
|
|
|
|
this.app.post("/api/user/login",
|
|
|
|
AuthenticationMWs.inverseAuthenticate,
|
|
|
|
AuthenticationMWs.login,
|
2016-03-26 11:19:10 +01:00
|
|
|
RenderingMWs.renderSessionUser
|
2016-03-19 17:31:42 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2016-05-16 23:15:03 +02:00
|
|
|
private addLogout() {
|
|
|
|
this.app.post("/api/user/logout",
|
|
|
|
AuthenticationMWs.authenticate,
|
|
|
|
AuthenticationMWs.logout,
|
|
|
|
RenderingMWs.renderOK
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-03-20 20:06:14 +01:00
|
|
|
private addGetSessionUser() {
|
|
|
|
this.app.get("/api/user/login",
|
|
|
|
AuthenticationMWs.authenticate,
|
2016-03-26 11:19:10 +01:00
|
|
|
RenderingMWs.renderSessionUser
|
2016-03-20 20:06:14 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2016-03-19 17:31:42 +01:00
|
|
|
|
|
|
|
private addChangePassword() {
|
2016-03-20 10:49:49 +01:00
|
|
|
this.app.post("/api/user/:id/password",
|
2016-03-19 17:31:42 +01:00
|
|
|
AuthenticationMWs.authenticate,
|
|
|
|
UserRequestConstrainsMWs.forceSelfRequest,
|
|
|
|
UserMWs.changePassword,
|
2016-03-26 11:19:10 +01:00
|
|
|
RenderingMWs.renderOK
|
2016-03-19 17:31:42 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
private addCreateUser() {
|
|
|
|
this.app.put("/api/user",
|
|
|
|
AuthenticationMWs.authenticate,
|
|
|
|
AuthenticationMWs.authorise(UserRoles.Admin),
|
|
|
|
UserMWs.createUser,
|
2016-03-26 11:19:10 +01:00
|
|
|
RenderingMWs.renderOK
|
2016-03-18 21:36:58 +01:00
|
|
|
);
|
|
|
|
};
|
2016-03-19 17:31:42 +01:00
|
|
|
|
|
|
|
private addDeleteUser() {
|
|
|
|
this.app.delete("/api/user/:id",
|
|
|
|
AuthenticationMWs.authenticate,
|
|
|
|
AuthenticationMWs.authorise(UserRoles.Admin),
|
|
|
|
UserRequestConstrainsMWs.notSelfRequest,
|
|
|
|
UserMWs.deleteUser,
|
2016-03-26 11:19:10 +01:00
|
|
|
RenderingMWs.renderOK
|
2016-03-19 17:31:42 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
private addListUsers() {
|
2016-05-03 14:29:24 +02:00
|
|
|
this.app.get("/api/user/list",
|
2016-03-19 17:31:42 +01:00
|
|
|
AuthenticationMWs.authenticate,
|
|
|
|
AuthenticationMWs.authorise(UserRoles.Admin),
|
2016-03-26 11:19:10 +01:00
|
|
|
UserMWs.listUsers,
|
|
|
|
RenderingMWs.renderResult
|
2016-03-19 17:31:42 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
private addChangeRole() {
|
2016-03-20 10:49:49 +01:00
|
|
|
this.app.post("/api/user/:id/role",
|
2016-03-19 17:31:42 +01:00
|
|
|
AuthenticationMWs.authenticate,
|
|
|
|
AuthenticationMWs.authorise(UserRoles.Admin),
|
|
|
|
UserRequestConstrainsMWs.notSelfRequestOr2Admins,
|
|
|
|
UserMWs.changeRole,
|
2016-03-26 11:19:10 +01:00
|
|
|
RenderingMWs.renderOK
|
2016-03-19 17:31:42 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-03-18 21:36:58 +01:00
|
|
|
}
|