From 417b247cf5b6e191ada3c3591cc002ebafc4dd3e Mon Sep 17 00:00:00 2001 From: LarsVomMars Date: Thu, 1 Oct 2020 17:04:39 +0200 Subject: AHHH --- db.js | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/db.js b/db.js index cd76e0a..398df92 100644 --- a/db.js +++ b/db.js @@ -29,31 +29,6 @@ class DB { for (const query of queries) await this.query(query); console.log("Tables created!"); }); - - fs.readFile(__dirname + "/names.csv", "utf8", (err, data) => { - if (err) throw err; - const classes = data.split("--"); - classes.forEach((clazz, classIndex) => { - const students = clazz.split("\n"); - students.forEach(async (student) => { - // Fix undefined - if (student && student.length > 3) { - const [_, surname, name] = student.split(","); - const names = name.split(" "); - const middlename = names.length > 1 && names[1] ? names.slice(1).join(" ") : null; - let username = surname.toLowerCase().slice(0, 6); - if (middlename) username += middlename[0].toLowerCase(); - username += names[0].toLowerCase().slice(0, 2); - const pwd = nanoid.nanoid(8); - const password = await bcrypt.hash(pwd, 12); - await this.query( - "INSERT INTO users (username, name, middlename, surname, password, class_id, type_id) VALUE (?,?,?,?,?,?,?)", - [username, names[0], middlename, surname, password, classIndex + 1, 2] - ); - } - }); - }); - }); } initValues() { -- cgit v1.2.3 From 91f4af6e9a3a5d770f98d4a5b75c729c18861cc1 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 1 Oct 2020 17:33:08 +0200 Subject: Some thingies --- auth/index.js | 5 ++++- auth/public/index.html | 4 ++-- db.js | 2 +- quotes/index.js | 22 ++++++++++++++++++++-- quotes/public/index.html | 6 +++--- quotes/public/script.js | 17 ++++------------- 6 files changed, 34 insertions(+), 22 deletions(-) diff --git a/auth/index.js b/auth/index.js index 9bc3f58..b726a25 100644 --- a/auth/index.js +++ b/auth/index.js @@ -9,6 +9,9 @@ const app = express.Router(); app.use("/", express.static(__dirname + "/public")); -app.get("/api/list", (req, res) => {}); +app.get("/api/list", async (req, res) => { + const users = await db.query("SELECT id, name, middlename, surname FROM users"); + res.json(users); +}); module.exports = app; diff --git a/auth/public/index.html b/auth/public/index.html index 8bf9ecd..e927b13 100644 --- a/auth/public/index.html +++ b/auth/public/index.html @@ -18,9 +18,9 @@
Login - + - +