aboutsummaryrefslogtreecommitdiff
path: root/auth/index.js
diff options
context:
space:
mode:
authorMarvin Borner2020-10-10 17:05:27 +0200
committerMarvin Borner2020-10-10 17:05:27 +0200
commit72f5731adeebf8d76c5c2dcc266f600ba57812d8 (patch)
tree4d774eb3d0464411a1bb09472c597298aa8965e8 /auth/index.js
parent167600b52eb03801bb7051a09dcb0e4f159cfb2a (diff)
Added basic admin interface
Diffstat (limited to 'auth/index.js')
-rw-r--r--auth/index.js18
1 files changed, 14 insertions, 4 deletions
diff --git a/auth/index.js b/auth/index.js
index 1ea6290..40062cc 100644
--- a/auth/index.js
+++ b/auth/index.js
@@ -4,14 +4,24 @@ const db = require("../db");
const app = express.Router();
-// TODO: Change passwords
-// TODO: Login (+ Frontend, cookie, etc)
-
function checkUser(req, res, next) {
if (req.session.loggedIn) next();
else res.redirect("/auth");
}
+function checkAdmin(req, res, next) {
+ if (!req.session.loggedIn) res.redirect("/auth");
+
+ try {
+ db.query("SELECT is_admin FROM users WHERE id = ?", [req.session.uid]).then((ret) => {
+ if (ret[0].is_admin == 1) next();
+ else res.redirect("/");
+ });
+ } catch (e) {
+ res.redirect("/");
+ }
+}
+
app.use(
"/",
(req, res, next) => {
@@ -81,4 +91,4 @@ app.get("/api/list", checkUser, async (req, res) => {
app.get("/api/status", (req, res) => res.json({ loggedIn: req.session.loggedIn }));
-module.exports = { auth: app, checkUser };
+module.exports = { auth: app, checkUser, checkAdmin };