diff options
-rw-r--r-- | app.js | 4 | ||||
-rw-r--r-- | auth/index.js | 12 | ||||
-rw-r--r-- | overview/public/index.html | 4 | ||||
-rw-r--r-- | profile.txt | 5 | ||||
-rw-r--r-- | profile/public/index.html | 4 | ||||
-rw-r--r-- | profile/public/script.js | 5 |
6 files changed, 23 insertions, 11 deletions
@@ -34,8 +34,8 @@ app.use(express.json()); app.use("/", express.static(__dirname + "/overview/public")); app.use("/mottovote", checkUser, mottovote); app.use("/quotes", checkUser, quotes); -// app.use("/poll", checkUser, poll); -// app.use("/profile", checkUser, profile); +app.use("/poll", checkUser, poll); +app.use("/profile", checkUser, profile); app.use("/admin", admin); // Lel app.use("/auth", auth); diff --git a/auth/index.js b/auth/index.js index 3109586..6514a8d 100644 --- a/auth/index.js +++ b/auth/index.js @@ -93,4 +93,16 @@ app.get("/api/status", (req, res) => { res.json({ loggedIn: req.session.loggedIn, admin: req.session.isAdmin }); }); +app.get("/api/self", checkUser, async (req, res) => { + try { + const user = await db.query( + "SELECT id, username, name, middlename, surname, class_id, type_id, is_admin FROM users WHERE id = ?", + [req.session.uid]); + res.json(user[0]); + } catch (e) { + console.error(e); + return res.send("error"); + } +}); + module.exports = { auth: app, checkUser, checkAdmin }; diff --git a/overview/public/index.html b/overview/public/index.html index a9546e8..9323a88 100644 --- a/overview/public/index.html +++ b/overview/public/index.html @@ -40,7 +40,7 @@ <li class="pure-menu-item"> <a href="/quotes" class="pure-menu-link">Zitate</a> </li> - <!--<li class="pure-menu-item"> + <li class="pure-menu-item"> <a href="/profile" class="pure-menu-link">Steckbrief</a> </li> <li class="pure-menu-item"> @@ -51,7 +51,7 @@ </li> <li class="pure-menu-item"> <a href="poll?type=teacher" class="pure-menu-link">Lehrer-Ranking</a> - </li>--> + </li> </ul> </div> <p> diff --git a/profile.txt b/profile.txt index acea013..66655f7 100644 --- a/profile.txt +++ b/profile.txt @@ -5,5 +5,6 @@ Am meisten werde ich vermissen - text Hobbies - text Zukunftspläne - text Lebensmotto/Seniorquote - text -Lieblingsbands/musiker/genre - text -Lieblingsfach/Hassfach - text +Lieblingsbands/-musiker/-genre - text +Lieblingsfach - text +Hassfach - text diff --git a/profile/public/index.html b/profile/public/index.html index fd7b507..672f409 100644 --- a/profile/public/index.html +++ b/profile/public/index.html @@ -19,11 +19,9 @@ <a href="/auth/api/logout" class="pure-menu-item pure-menu-link">Logout</a> </div> <main> - <h1 id="username"></h1> + <h2 id="username"></h2> <form class="pure-form pure-form-stacked"> <fieldset> - <legend>Steckbrief</legend> - <!-- TODO: Consider autosave --> <button type="submit" class="pure-button pure-button-primary">Wohooo</button> </fieldset> diff --git a/profile/public/script.js b/profile/public/script.js index 3b39460..b927f9f 100644 --- a/profile/public/script.js +++ b/profile/public/script.js @@ -3,7 +3,7 @@ const form = document.querySelector("form"); let init = true; function updateHeading(user) { - document.getElementById("username").textContent = `${user.name} ${user.surname}`; + document.getElementById("username").textContent = `Steckbrief: ${user.name} ${user.middlename || ""} ${user.surname}`; } function appendQuestions(question) { @@ -51,7 +51,8 @@ form.addEventListener("submit", async (evt) => { if (res !== "ok") alert("AHHHH"); else location.reload(); }); -fetch("api/user") + +fetch("/auth/api/self") .then((response) => response.json()) .then(updateHeading) .catch(console.error); |