#15-invite-user #16
6 changed files with 77 additions and 9 deletions
|
@ -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<any> {}
|
||||
|
||||
/**
|
||||
* @description start first user
|
||||
* @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 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<any> {
|
|||
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<any> {
|
||||
const id = parseInt(req.params.id);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
37
src/routes/admin/invite.ts
Normal file
37
src/routes/admin/invite.ts
Normal 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;
|
|
@ -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"),
|
||||
|
|
|
@ -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);
|
||||
|
|
16
src/routes/invite.ts
Normal file
16
src/routes/invite.ts
Normal 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;
|
Loading…
Reference in a new issue