aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLarsVomMars2020-10-01 22:34:59 +0200
committerLarsVomMars2020-10-01 22:34:59 +0200
commitf052c14c6f0ef746b56cdf6c75d5549bff822336 (patch)
treec4fa85ac1bc22284bec9828d85a2f326a5265e72
parentfcf69961fcb1d5044d36667c6ba904c71bad8946 (diff)
User dump improvement
-rw-r--r--db.js7
1 files changed, 4 insertions, 3 deletions
diff --git a/db.js b/db.js
index ab6a7f2..27fa9e7 100644
--- a/db.js
+++ b/db.js
@@ -38,13 +38,14 @@ class DB {
fs.readFile(__dirname + "/names.csv", "utf8", async (err, data) => {
if (err) throw err;
const classes = data.split("--");
- const userPasswords = [];
+ const userPasswords = {};
console.log("Generating users");
for (const [classIndex, clazz] of classes.entries()) {
const students = clazz.split("\n");
+ userPasswords[classIndex] = [];
// students.forEach(async (student) => {
for (const student of students) {
- console.log(".");
+ // console.log(".");
// Fix undefined
if (student && student.length > 3) {
const [_, surname, name] = student.split(",");
@@ -55,7 +56,7 @@ class DB {
username += names[0].toLowerCase().slice(0, 2);
const pwd = nanoid.nanoid(8);
const password = await bcrypt.hash(pwd, 12);
- userPasswords.push({ username, pwd });
+ userPasswords[classIndex].push({ username, pwd });
await this.query(
"INSERT INTO users (username, name, middlename, surname, password, class_id, type_id) VALUE (?,?,?,?,?,?,?)",
[username, names[0].replace("\r", ""), middlename, surname, password, classIndex + 1, 2]