diff --git a/src/controller/inviteController.ts b/src/controller/inviteController.ts index a6ff7eb..f169110 100644 --- a/src/controller/inviteController.ts +++ b/src/controller/inviteController.ts @@ -19,6 +19,14 @@ import { CLUB_NAME } from "../env.defaults"; import { CreateUserPermissionCommand } from "../command/userPermissionCommand"; import UserPermissionCommandHandler from "../command/userPermissionCommandHandler"; +/** + * @description get all invites + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getInvites(req: Request, res: Response): Promise {} + /** * @description start first user * @param req {Request} Express req object @@ -78,7 +86,7 @@ export async function verifyInvite(req: Request, res: Response): Promise { let mail = req.body.mail; let token = req.body.token; - let { secret } = await InviteService.getByMailAndToken(mail, token); + let { secret, username } = await InviteService.getByMailAndToken(mail, token); const url = `otpauth://totp/Mitgliederverwaltung ${CLUB_NAME}?secret=${secret}`; @@ -87,6 +95,7 @@ export async function verifyInvite(req: Request, res: Response): Promise { res.json({ dataUrl: result, otp: secret, + username, }); }) .catch((err) => { @@ -146,3 +155,13 @@ export async function finishInvite(req: Request, res: Response, grantAdmin: bool refreshToken, }); } + +/** + * @description delete invites + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function deleteInvites(req: Request, res: Response): Promise { + const id = parseInt(req.params.id); +} diff --git a/src/routes/admin/index.ts b/src/routes/admin/index.ts index cdafa5e..3df08e7 100644 --- a/src/routes/admin/index.ts +++ b/src/routes/admin/index.ts @@ -14,6 +14,7 @@ import calendar from "./calendar"; import role from "./role"; import user from "./user"; +import invite from "./invite"; var router = express.Router({ mergeParams: true }); @@ -42,5 +43,6 @@ router.use("/calendar", PermissionHelper.passCheckMiddleware("read", "club", "ca router.use("/role", PermissionHelper.passCheckMiddleware("read", "user", "role"), role); router.use("/user", PermissionHelper.passCheckMiddleware("read", "user", "user"), user); +router.use("/invite", PermissionHelper.passCheckMiddleware("read", "user", "user"), invite); export default router; diff --git a/src/routes/admin/invite.ts b/src/routes/admin/invite.ts new file mode 100644 index 0000000..f1e5136 --- /dev/null +++ b/src/routes/admin/invite.ts @@ -0,0 +1,37 @@ +import express, { Request, Response } from "express"; +import PermissionHelper from "../../helpers/permissionHelper"; +import { + deleteUser, + getAllUsers, + getUserById, + getUserPermissions, + getUserRoles, + updateUser, + updateUserPermissions, + updateUserRoles, +} from "../../controller/admin/userController"; +import { inviteUser } from "../../controller/inviteController"; + +var router = express.Router({ mergeParams: true }); + +router.get("/", async (req: Request, res: Response) => { + await getAllUsers(req, res); +}); + +router.post( + "/invite", + PermissionHelper.passCheckMiddleware("create", "user", "user"), + async (req: Request, res: Response) => { + await inviteUser(req, res); + } +); + +router.delete( + "/:id", + PermissionHelper.passCheckMiddleware("delete", "user", "user"), + async (req: Request, res: Response) => { + //await deleteUser(req, res); + } +); + +export default router; diff --git a/src/routes/admin/user.ts b/src/routes/admin/user.ts index 7ce7046..8bfd44b 100644 --- a/src/routes/admin/user.ts +++ b/src/routes/admin/user.ts @@ -30,14 +30,6 @@ router.get("/:id/roles", async (req: Request, res: Response) => { await getUserRoles(req, res); }); -router.post( - "/invite", - PermissionHelper.passCheckMiddleware("create", "user", "user"), - async (req: Request, res: Response) => { - await inviteUser(req, res); - } -); - router.patch( "/:id", PermissionHelper.passCheckMiddleware("update", "user", "user"), diff --git a/src/routes/index.ts b/src/routes/index.ts index 5025c17..eee3e7d 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -8,6 +8,7 @@ import errorHandler from "../middleware/errorHandler"; import publicAvailable from "./public"; import setup from "./setup"; +import invite from "./invite"; import reset from "./reset"; import auth from "./auth"; import admin from "./admin/index"; @@ -27,6 +28,7 @@ export default (app: Express) => { app.use("/public", publicAvailable); app.use("/setup", allowSetup, setup); app.use("/reset", reset); + app.use("/invite", invite); app.use("/auth", auth); app.use(authenticate); app.use("/admin", admin); diff --git a/src/routes/invite.ts b/src/routes/invite.ts new file mode 100644 index 0000000..783ecef --- /dev/null +++ b/src/routes/invite.ts @@ -0,0 +1,16 @@ +import express from "express"; +import { isSetup } from "../controller/setupController"; +import { finishInvite, inviteUser, verifyInvite } from "../controller/inviteController"; +import ParamaterPassCheckHelper from "../helpers/parameterPassCheckHelper"; + +var router = express.Router({ mergeParams: true }); + +router.post("/verify", ParamaterPassCheckHelper.requiredIncludedMiddleware(["mail", "token"]), async (req, res) => { + await verifyInvite(req, res); +}); + +router.put("/", ParamaterPassCheckHelper.requiredIncludedMiddleware(["mail", "token", "totp"]), async (req, res) => { + await finishInvite(req, res); +}); + +export default router;