preliminary work for guest account support
This commit is contained in:
parent
b6779a7d7c
commit
bbc655b3f9
11 changed files with 132 additions and 50 deletions
30
app/routes/adduser.ts
Normal file
30
app/routes/adduser.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import type {RequestHandler as Middleware, Router, Request, Response, NextFunction} from 'express';
|
||||
import express from "express";
|
||||
|
||||
import {db, createUser} from "../db";
|
||||
|
||||
const router: Router = express.Router();
|
||||
|
||||
const adminCheck: Middleware = (req: Request, res: Response, next: NextFunction) => {
|
||||
//@ts-ignore
|
||||
if (!req.user)
|
||||
return res.status(403).send("You are not authorized to perform this action");
|
||||
else {
|
||||
//@ts-ignore
|
||||
if (req.user.username != "admin")
|
||||
return res.status(403).send("You are not authorized to perform this action");
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
router.get("/adduser", adminCheck, (req: Request, res: Response, next: NextFunction) => {
|
||||
res.locals.filter = null;
|
||||
res.render("adduser", { user: req.user });
|
||||
});
|
||||
|
||||
router.post("/adduser", adminCheck, (req: Request, res: Response, next: NextFunction) => {
|
||||
createUser(req.body.username, req.body.password);
|
||||
res.redirect('/');
|
||||
});
|
||||
|
||||
export default router;
|
Loading…
Add table
Add a link
Reference in a new issue