From 6641f50d8421a440b5eee397ecd58efaf7eb7ef8 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Wed, 8 Aug 2018 18:58:27 +0000 Subject: [server/database] Delete old database lib Because of the use of sequelize, the old mysql database lib becomes unnecessary. Remove old code that was not used anymore. --- server/lib/authentication.js | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'server/lib/authentication.js') diff --git a/server/lib/authentication.js b/server/lib/authentication.js index b8ee506..a9ee4ef 100644 --- a/server/lib/authentication.js +++ b/server/lib/authentication.js @@ -2,7 +2,6 @@ var jwt = require('jsonwebtoken') var path = require('path') var config = require(path.join(__appdir, 'config', 'authentication')) -// var db = require(path.join(__appdir, 'lib', 'database')).connectionPool; var db = require(path.join(__appdir, 'lib', 'sequelize')) var securePassword = require('secure-password') var pwd = securePassword() @@ -42,11 +41,8 @@ module.exports = { if (!params.password) return res.status(500).send({ auth: false, status: 'PASSWORD_MISSING', error_message: 'This services requires a password.' }) if (!params.email) return res.status(500).send({ auth: false, status: 'EMAIL_MISSING', error_message: 'This services requires an email.' }) // Database and user validation. - // SEQ//db.query('SELECT * FROM users WHERE username = ?', [params.username], function (err, rows) { db.user.findOne({ where: { username: params.username } }).then(userDb => { - // SEQ//if (err) return res.status(500).send({ auth: false, status: 'DATABASE_ERROR', error_message: 'SQL query failed.' }); // User exists validation. - // SEQ//if (rows.length) return res.status(500).send({ auth: false, status: 'USER_ALREADY_EXISTS', error_message: 'The provided username already exists.' }); if (userDb) return res.status(500).send({ auth: false, status: 'USER_ALREADY_EXISTS', error_message: 'The provided username already exists.' }) // Password requirements validation. @@ -58,12 +54,8 @@ module.exports = { pwd.hash(userPassword, function (err, hash) { if (err) return res.status(500).send({ auth: false, status: 'PASSWORD_HASH_ERROR', error_message: 'Hashing the password failed.' }) // Saving the non improved hash and creating the user in the db. - // SEQ//var att = [params.username, hash, params.email, params.name]; - // SEQ//db.query('INSERT INTO users (username, password, email, name) VALUES (?)', [att], function (err, result) { db.user.create({ username: params.username, password: hash, email: params.email, name: params.name }).then((userDb) => { - // SEQ//if (err) return res.status(500).send({ auth: false, status: 'DATABASE_INSERT_ERROR', error_message: 'Inserting the user in the database failed.' }); // TODO: Username could also be used because those are unique as well. - // SEQ//var userId = result.insertId; var userId = userDb.id // Verify & improving the hash. @@ -116,22 +108,13 @@ function verifyUser (res, username, password, callback) { if (!username) return res.status(500).send({ auth: false, status: 'USER_MISSING', error_message: 'This service requires an username.' }) if (!password) return res.status(500).send({ auth: false, status: 'PASSWORD_MISSING', error_message: 'This services requires a password.' }) - // SEQ//db.query('SELECT * FROM users WHERE username = ?', [username], function (err, rows) { db.user.findOne({ where: { username: username } }).then(userDb => { - // SEQ//if (err) return res.status(500).send({ auth: false, status: 'DATABASE_ERROR', error_message: 'Database connection failed.' }); - // SEQ//if (rows.length != 1) { - // SEQ// return res.status(404).send({ auth: false, status: 'USER_NOTFOUND', error_message: 'User does not exist.' }); - // SEQ//} if (!userDb) { return res.status(404).send({ auth: false, status: 'USER_NOTFOUND', error_message: 'User does not exist.' }) } var user = {} - // SEQ//user.id = rows[0].id; user.id = userDb.id - // user.username = rows[0].username; - // user.email = rows[0].email; var userPassword = Buffer.from(password) - // SEQ//var hash = Buffer.from(rows[0].password); var hash = Buffer.from(userDb.password) // Verify & improving the hash. @@ -165,9 +148,7 @@ function verifyHash (res, password, hash, userId, callback) { if (err) throw err // Update the improved hash in the db. - // SEQ//db.query('UPDATE users SET password=? WHERE id=?', [improvedHash, userId], function (err, result) { db.user.findOne({ where: { id: userId } }).then(user => { - // SEQ//if (err) throw err; user.updateAttributes({ password: improvedHash }) @@ -180,7 +161,6 @@ function verifyHash (res, password, hash, userId, callback) { // Function for validating the e-mail. function validateEmail (email) { -// var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ // Removed escape before [ because eslint told me so. var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ return re.test(String(email).toLowerCase()) -- cgit v1.2.3-55-g7522