aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-10-10 18:37:26 +0200
committerMarvin Borner2020-10-10 18:37:26 +0200
commit16ebbb932c0b780c11d3e574bc24a515eb095f5f (patch)
tree1542c555ff8772f20bb4a280dffb5995eaf7103f
parent00409448b34265d976485095eadc579bde5cab57 (diff)
Fixed navbar if not logged in
-rw-r--r--auth/index.js10
-rw-r--r--auth/public/index.html1
-rw-r--r--overview/public/index.html7
-rw-r--r--overview/public/script.js22
4 files changed, 36 insertions, 4 deletions
diff --git a/auth/index.js b/auth/index.js
index 40062cc..e40ea43 100644
--- a/auth/index.js
+++ b/auth/index.js
@@ -89,6 +89,14 @@ app.get("/api/list", checkUser, async (req, res) => {
res.json(users);
});
-app.get("/api/status", (req, res) => res.json({ loggedIn: req.session.loggedIn }));
+app.get("/api/status", (req, res) => {
+ if (req.session.loggedIn) {
+ db.query("SELECT is_admin FROM users WHERE id = ?", [req.session.uid]).then((ret) => {
+ res.json({ loggedIn: req.session.loggedIn, admin: ret[0].is_admin ? true : false });
+ });
+ } else {
+ res.json({ loggedIn: false, admin: false });
+ }
+});
module.exports = { auth: app, checkUser, checkAdmin };
diff --git a/auth/public/index.html b/auth/public/index.html
index b56db07..8273238 100644
--- a/auth/public/index.html
+++ b/auth/public/index.html
@@ -16,7 +16,6 @@
<body>
<div class="pure-menu pure-menu-horizontal">
<a href="/" class="pure-menu-item pure-menu-link">Home</a>
- <a href="/auth/api/logout" class="pure-menu-item pure-menu-link">Logout</a>
</div>
<form class="pure-form pure-form-stacked" action="api/login" method="post">
diff --git a/overview/public/index.html b/overview/public/index.html
index c97b83f..f9bc2d8 100644
--- a/overview/public/index.html
+++ b/overview/public/index.html
@@ -15,8 +15,9 @@
</head>
<body>
<div class="pure-menu pure-menu-horizontal">
- <a href="/auth/change.html" class="pure-menu-item pure-menu-link">Passwort ändern</a>
- <a href="/auth/api/logout" class="pure-menu-item pure-menu-link">Logout</a>
+ <a href="" class="pure-menu-item pure-menu-link"></a>
+ <a href="" class="pure-menu-item pure-menu-link"></a>
+ <a href="" class="pure-menu-item pure-menu-link"></a>
</div>
<div class="card">
<h2>Hallo, liebe RBS-Schüler*innen!</h2>
@@ -45,5 +46,7 @@
<li><a href="https://github.com/marvinborner/Abizeugs/">Öffentlicher Source-Code</a></li>
</ul>
</div>
+
+ <script src="script.js"></script>
</body>
</html>
diff --git a/overview/public/script.js b/overview/public/script.js
new file mode 100644
index 0000000..be058b7
--- /dev/null
+++ b/overview/public/script.js
@@ -0,0 +1,22 @@
+fetch("/auth/api/status").then(response => response.json()).then(response => {
+ console.log(response);
+ const first = document.querySelectorAll("a")[0];
+ const second = document.querySelectorAll("a")[1];
+ const third = document.querySelectorAll("a")[2];
+
+ if (!response.admin)
+ third.style.display = "none";
+
+ if (response.loggedIn) {
+ first.href = "/auth/change.html";
+ first.innerText = "Passwort ändern";
+ second.href = "/auth/api/logout";
+ second.innerText = "Logout";
+ if (response.admin) {
+ third.href = "/admin";
+ third.innerText = "Administration";
+ }
+ } else {
+ document.querySelectorAll("div.pure-menu")[0].style.display = "none";
+ }
+});