#15-invite-user #16

Merged
jkeffects merged 2 commits from #15-invite-user into main 2024-11-24 11:36:56 +00:00
6 changed files with 77 additions and 9 deletions
Showing only changes of commit d1cf9f4c66 - Show all commits

View file

@ -19,6 +19,14 @@ import { CLUB_NAME } from "../env.defaults";
import { CreateUserPermissionCommand } from "../command/userPermissionCommand"; import { CreateUserPermissionCommand } from "../command/userPermissionCommand";
import UserPermissionCommandHandler from "../command/userPermissionCommandHandler"; 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<any> {}
/** /**
* @description start first user * @description start first user
* @param req {Request} Express req object * @param req {Request} Express req object
@ -78,7 +86,7 @@ export async function verifyInvite(req: Request, res: Response): Promise<any> {
let mail = req.body.mail; let mail = req.body.mail;
let token = req.body.token; 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}`; const url = `otpauth://totp/Mitgliederverwaltung ${CLUB_NAME}?secret=${secret}`;
@ -87,6 +95,7 @@ export async function verifyInvite(req: Request, res: Response): Promise<any> {
res.json({ res.json({
dataUrl: result, dataUrl: result,
otp: secret, otp: secret,
username,
}); });
}) })
.catch((err) => { .catch((err) => {
@ -146,3 +155,13 @@ export async function finishInvite(req: Request, res: Response, grantAdmin: bool
refreshToken, 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<any> {
const id = parseInt(req.params.id);
}

View file

@ -14,6 +14,7 @@ import calendar from "./calendar";
import role from "./role"; import role from "./role";
import user from "./user"; import user from "./user";
import invite from "./invite";
var router = express.Router({ mergeParams: true }); 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("/role", PermissionHelper.passCheckMiddleware("read", "user", "role"), role);
router.use("/user", PermissionHelper.passCheckMiddleware("read", "user", "user"), user); router.use("/user", PermissionHelper.passCheckMiddleware("read", "user", "user"), user);
router.use("/invite", PermissionHelper.passCheckMiddleware("read", "user", "user"), invite);
export default router; export default router;

View file

@ -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;

View file

@ -30,14 +30,6 @@ router.get("/:id/roles", async (req: Request, res: Response) => {
await getUserRoles(req, res); await getUserRoles(req, res);
}); });
router.post(
"/invite",
PermissionHelper.passCheckMiddleware("create", "user", "user"),
async (req: Request, res: Response) => {
await inviteUser(req, res);
}
);
router.patch( router.patch(
"/:id", "/:id",
PermissionHelper.passCheckMiddleware("update", "user", "user"), PermissionHelper.passCheckMiddleware("update", "user", "user"),

View file

@ -8,6 +8,7 @@ import errorHandler from "../middleware/errorHandler";
import publicAvailable from "./public"; import publicAvailable from "./public";
import setup from "./setup"; import setup from "./setup";
import invite from "./invite";
import reset from "./reset"; import reset from "./reset";
import auth from "./auth"; import auth from "./auth";
import admin from "./admin/index"; import admin from "./admin/index";
@ -27,6 +28,7 @@ export default (app: Express) => {
app.use("/public", publicAvailable); app.use("/public", publicAvailable);
app.use("/setup", allowSetup, setup); app.use("/setup", allowSetup, setup);
app.use("/reset", reset); app.use("/reset", reset);
app.use("/invite", invite);
app.use("/auth", auth); app.use("/auth", auth);
app.use(authenticate); app.use(authenticate);
app.use("/admin", admin); app.use("/admin", admin);

16
src/routes/invite.ts Normal file
View file

@ -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;