diff --git a/package-lock.json b/package-lock.json index dd91a0c..8ccc96d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "app-root-path": "^3.1.0", "dotenv": "^16.4.7", "express": "^4.21.2", "express-session": "^1.18.1", @@ -29,6 +30,15 @@ "node": ">= 0.6" } }, + "node_modules/app-root-path": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/app-root-path/-/app-root-path-3.1.0.tgz", + "integrity": "sha512-biN3PwB2gUtjaYy/isrU3aNWI5w+fAfvHkSvCKeQGxhmYpwKFUxudR3Yya+KqVRHBmEDYh+/lTozYCFbmzX4nA==", + "license": "MIT", + "engines": { + "node": ">= 6.0.0" + } + }, "node_modules/array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", diff --git a/package.json b/package.json index c7934d8..c391410 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "license": "ISC", "description": "Webshop Autohändler", "dependencies": { + "app-root-path": "^3.1.0", "dotenv": "^16.4.7", "express": "^4.21.2", "express-session": "^1.18.1", diff --git a/scripts/modules/login.js b/scripts/modules/login.js index 454dccc..e265f91 100644 --- a/scripts/modules/login.js +++ b/scripts/modules/login.js @@ -5,8 +5,23 @@ let userInput = "test1" let appRoot = require('app-root-path') let dbConnect = require(appRoot + '/scripts/modules/db-connect.js') -dbConnect.query("SELECT * FROM webshop.user WHERE email = " + "'" + userInput + "'", function (err, result) { - if (err) throw err - console.log(result) +dbConnect.query("SELECT is_active, name, passwd FROM webshop.user WHERE email = " + "'" + userInput + "'", async (err, result) => { + if (err) + console.log(err) + + if(result.length > 0){ + // tell user "email is already in use" + } else if (passwd !== passwd_confirm){ + // tell user "passwords do not match" + } + let hashedPasswd = await bcrypt.hash(password, 8) + + dbConnect.query('INSERT INTO user SET?', {name: name, email: email, passwd: hashedPasswd}, (err, res) => { + if(err) + console.log(err) + else{ + // tell user "user registered" + } + }) }) dbConnect.end() \ No newline at end of file