From 18ef321eeaca33fefd9eec035ccbde251e6e7ca6 Mon Sep 17 00:00:00 2001 From: Robert Richter Date: Thu, 20 Dec 2018 20:07:38 +0100 Subject: [PATCH] Vorbereitung von Benutzeranmeldung --- server/app_cfg.js | 3 +++ server/sql_cfg.js | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/server/app_cfg.js b/server/app_cfg.js index 671c92f..308be93 100644 --- a/server/app_cfg.js +++ b/server/app_cfg.js @@ -6,6 +6,9 @@ app_cfg.global = { database: './database.sqlite3', soundpath: '/public/media/', mediapath: '/media/', + defaultuser: 'me', + defaultpass: '123', + saltRounds: 10, // TODO: eindeutige ID/Version für Anwendung hinterlegen // TODO: Karten-URL für Client festlegen app_id: process.pid diff --git a/server/sql_cfg.js b/server/sql_cfg.js index 065b0b5..3c5a2b2 100644 --- a/server/sql_cfg.js +++ b/server/sql_cfg.js @@ -1,4 +1,4 @@ -module.exports = function(app_cfg) { +module.exports = function(bcrypt, app_cfg) { // TODO: gegen better-sqlite3 ersetzen @@ -73,6 +73,12 @@ module.exports = function(app_cfg) { client_ip TEXT, room_name TEXT, client_status TEXT)`); + // Benutzer-Tabelle erstellen + db.run(`CREATE TABLE waip_users ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + user TEXT, + password TEXT, + permissions TEXT)`); // Ersetzungs-Tabelle fuer Einsatzmittelnamen erstellen db.run(`CREATE TABLE waip_ttsreplace ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, @@ -783,6 +789,21 @@ module.exports = function(app_cfg) { (\'83\',\'RTW\'), (\'85\',\'KTW\'), (\'88\',\'Rettungsboot\')`); + // Benutzer-Tabelle mit Standard befuellen + db.get("SELECT user from waip_users", function(err, row) { + if (!row) { + /*bcrypt.hash('a', 1, function(err, hash) { + console.log(hash); + });*/ + }; + }); + /*bcrypt.hash(app_cfg.global.defaultpass, app_cfg.global.saltRounds, function(err, hash) { + db.run(`INSERT INTO waip_users ( user, password, permissions ) VALUES( ?, ?, 'admin' )`, app_cfg.global.defaultuser, hash, function(err) { + if (err) { + console.log(err); + }; + }); + });*/ }); };