diff options
author | Marvin Borner | 2020-10-10 23:04:31 +0200 |
---|---|---|
committer | Marvin Borner | 2020-10-10 23:04:31 +0200 |
commit | d32ffe5d0e44f591adcf692b98a43efb5e65187a (patch) | |
tree | 25733d3e2a3829315f2cf50cf3f817cea4221e08 | |
parent | 5017a820ab9c0d49b3db370421f9856c8b709647 (diff) |
Formatting
-rw-r--r-- | auth/index.js | 14 | ||||
-rw-r--r-- | db.js | 6 | ||||
-rw-r--r-- | overview/public/index.html | 2 | ||||
-rw-r--r-- | overview/public/script.js | 41 | ||||
-rw-r--r-- | profile/index.js | 20 | ||||
-rw-r--r-- | quotes/public/index.html | 12 |
6 files changed, 50 insertions, 45 deletions
diff --git a/auth/index.js b/auth/index.js index e40ea43..3ef330d 100644 --- a/auth/index.js +++ b/auth/index.js @@ -38,7 +38,7 @@ app.post("/api/login", async (req, res) => { const { username, password } = req.body; if (!(username && password)) return res.redirect("/auth"); const user = (await db.query("SELECT id, password FROM users WHERE username = ?", [username]))[0]; - if (!user.password) return res.redirect("/auth"); + if (!user || !user.password) return res.redirect("/auth"); const loggedIn = await bcrypt.compare(password, user.password); if (loggedIn) { req.session.loggedIn = true; @@ -53,7 +53,7 @@ app.post("/api/password", checkUser, async (req, res) => { const { oldPassword, newPassword, newPasswordRep } = req.body; if (!(oldPassword && newPassword && newPasswordRep) || newPassword !== newPasswordRep) return res.send("error"); const user = (await db.query("SELECT id, password FROM users WHERE id = ?", [req.session.uid]))[0]; - if (!user.password) return res.send("error"); + if (!user || !user.password) return res.send("error"); if (req.session.loggedIn && user.id === req.session.uid) return res.redirect("/auth"); if (!(await bcrypt.compare(oldPassword, user.password))) return res.send("error"); try { @@ -90,13 +90,13 @@ app.get("/api/list", checkUser, async (req, res) => { }); app.get("/api/status", (req, res) => { - if (req.session.loggedIn) { + 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 }); + res.json({ loggedIn: req.session.loggedIn, admin: ret[0].is_admin ? true : false }); }); - } else { - res.json({ loggedIn: false, admin: false }); - } + } else { + res.json({ loggedIn: false, admin: false }); + } }); module.exports = { auth: app, checkUser, checkAdmin }; @@ -40,7 +40,6 @@ class DB { "INSERT INTO class (name) VALUES ('TGM13.1'), ('TGM13.2'), ('TGTM13.1'), ('TGI13.1'), ('TGI13.2'), ('teacher')", ); - const types = ["number", "file", "date", "text", "color"]; await this.query("INSERT INTO profile_input_types (type) VALUES (?), (?), (?), (?), (?)", types); @@ -80,7 +79,10 @@ class DB { questions.forEach((question) => { if (question) { const [q, type] = question.split(" - "); - this.query("INSERT INTO profile_questions (question, question_type) VALUE (?, ?)", [q, types.indexOf(type) + 1]); + this.query("INSERT INTO profile_questions (question, question_type) VALUE (?, ?)", [ + q, + types.indexOf(type) + 1, + ]); } }); }); diff --git a/overview/public/index.html b/overview/public/index.html index 6f63353..b9c08bb 100644 --- a/overview/public/index.html +++ b/overview/public/index.html @@ -47,6 +47,6 @@ </ul> </div> - <script src="script.js"></script> + <script src="script.js"></script> </body> </html> diff --git a/overview/public/script.js b/overview/public/script.js index 68b2d5a..d7e5b71 100644 --- a/overview/public/script.js +++ b/overview/public/script.js @@ -1,22 +1,23 @@ -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]; +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.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 = "Admin"; - } - } else { - document.querySelectorAll("div.pure-menu")[0].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 = "Admin"; + } + } else { + document.querySelectorAll("div.pure-menu")[0].style.display = "none"; + } + }); diff --git a/profile/index.js b/profile/index.js index 1c5752f..ac46304 100644 --- a/profile/index.js +++ b/profile/index.js @@ -7,7 +7,7 @@ app.use(fileupload({})); app.use("/", express.static(__dirname + "/public/")); -app.get("/user/:uid", async (req, res) => { }); +app.get("/user/:uid", async (req, res) => {}); // Basic API app.get("/api/user", async (req, res) => { @@ -16,7 +16,9 @@ app.get("/api/user", async (req, res) => { }); app.get("/api/questions", async (req, res) => { - const questions = await db.query("SELECT q.id, q.question, t.type FROM profile_questions q INNER JOIN profile_input_types t ON t.id = q.question_type"); + const questions = await db.query( + "SELECT q.id, q.question, t.type FROM profile_questions q INNER JOIN profile_input_types t ON t.id = q.question_type", + ); const answers = await db.query("SELECT answer, question_id FROM profile_answers WHERE user_id = ?", [ req.session.uid, ]); @@ -36,7 +38,7 @@ app.post("/api/add", async (req, res) => { await db.query("INSERT INTO profile_answers (question_id, user_id, answer) VALUES (?, ?, ?)", [ qid, req.session.uid, - answer + answer, ]); } for (let fid in req.files) { @@ -46,7 +48,7 @@ app.post("/api/add", async (req, res) => { image = req.files[fid]; imageType = image.name.split(".").reverse()[0]; - imageName = `${req.session.uid}_${(new Date()).getTime()}.${imageType}`; + imageName = `${req.session.uid}_${new Date().getTime()}.${imageType}`; image.mv(__dirname + "/public/uploads/" + imageName); await db.query("INSERT INTO profile_answers (question_id, user_id, answer) VALUES (?, ?, ?)", [ qid, @@ -79,7 +81,7 @@ app.put("/api/update", async (req, res) => { image = req.files[fid]; imageType = image.name.split(".").reverse()[0]; - imageName = `${req.session.uid}_${(new Date()).getTime()}.${imageType}`; + imageName = `${req.session.uid}_${new Date().getTime()}.${imageType}`; image.mv(__dirname + "/public/uploads/" + imageName); await db.query("UPDATE profile_answers SET answer = ? WHERE question_id = ? AND user_id = ?", [ imageName, @@ -95,12 +97,12 @@ app.put("/api/update", async (req, res) => { }); // Comments API -app.get("/api/comments/:uid", async (req, res) => { }); +app.get("/api/comments/:uid", async (req, res) => {}); -app.post("/api/comment", async (req, res) => { }); +app.post("/api/comment", async (req, res) => {}); -app.put("/api/comment", async (req, res) => { }); +app.put("/api/comment", async (req, res) => {}); -app.delete("/api/comment", async (req, res) => { }); +app.delete("/api/comment", async (req, res) => {}); module.exports = app; diff --git a/quotes/public/index.html b/quotes/public/index.html index b91d1e1..8853ee4 100644 --- a/quotes/public/index.html +++ b/quotes/public/index.html @@ -32,17 +32,17 @@ </form> <button id="open_TGI13.1">TGI13.1</button> - <ul style="display: none;" id="TGI13.1"></ul> + <ul style="display: none" id="TGI13.1"></ul> <button id="open_TGI13.2">TGI13.2</button> - <ul style="display: none;" id="TGI13.2"></ul> + <ul style="display: none" id="TGI13.2"></ul> <button id="open_TGM13.1">TGM13.1</button> - <ul style="display: none;" id="TGM13.1"></ul> + <ul style="display: none" id="TGM13.1"></ul> <button id="open_TGM13.2">TGM13.2</button> - <ul style="display: none;" id="TGM13.2"></ul> + <ul style="display: none" id="TGM13.2"></ul> <button id="open_TGTM13.1">TGTM13.1</button> - <ul style="display: none;" id="TGTM13.1"></ul> + <ul style="display: none" id="TGTM13.1"></ul> <button id="open_teacher">Lehrer</button> - <ul style="display: none;" id="teacher"></ul> + <ul style="display: none" id="teacher"></ul> </main> <script src="script.js" charset="utf-8"></script> |