From e00547732bd9c701546cacaa98a073d50caa6ec4 Mon Sep 17 00:00:00 2001 From: LarsVomMars Date: Fri, 2 Oct 2020 14:10:51 +0200 Subject: Super duper fixibus --- db.js | 9 +++------ tables.sql | 8 ++++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/db.js b/db.js index f3b3b18..da082dc 100644 --- a/db.js +++ b/db.js @@ -12,9 +12,6 @@ class DB { database: process.env.DBName, }); this.init(); - this.query("SELECT * FROM users LIMIT 1").then((res) => { - if (res.length === 0) this.initValues(); - }); } connect() { @@ -38,9 +35,9 @@ class DB { fs.readFile(__dirname + "/names.csv", "utf8", async (err, data) => { if (err) throw err; - await this.query("INSERT INTO types (name) VALUES ('teacher'), ('puipl')"); + await this.query("INSERT INTO types (name) VALUES ('teacher'), ('pupil')"); await this.query( - "INSERT INTO class (name) VALUES ('TGM13.1'), ('TGM13.2'), (TGTM13.1), (TGI13.1), (TGI13.2)" + "INSERT INTO class (name) VALUES ('TGM13.1'), ('TGM13.2'), ('TGTM13.1'), ('TGI13.1'), ('TGI13.2')" ); const classes = data.split("--"); @@ -61,7 +58,7 @@ class DB { 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); + const password = await bcrypt.hash(pwd, 10); userPasswords[classIndex].push({ username, pwd }); await this.query( "INSERT INTO users (username, name, middlename, surname, password, class_id, type_id) VALUE (?,?,?,?,?,?,?)", diff --git a/tables.sql b/tables.sql index 8948860..d9b9694 100644 --- a/tables.sql +++ b/tables.sql @@ -9,10 +9,10 @@ CREATE TABLE IF NOT EXISTS theme( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- TODO: Remove dropping --- DROP TABLE IF EXISTS quotes; --- DROP TABLE IF EXISTS users; --- DROP TABLE IF EXISTS types; --- DROP TABLE IF EXISTS class; +DROP TABLE IF EXISTS quotes; +DROP TABLE IF EXISTS users; +DROP TABLE IF EXISTS types; +DROP TABLE IF EXISTS class; CREATE TABLE IF NOT EXISTS types( id INTEGER PRIMARY KEY AUTO_INCREMENT, -- cgit v1.2.3