From 957b531b521de886e17eee2f55088ef42423a0fb Mon Sep 17 00:00:00 2001 From: Rosanny <rosanny.sihombing@hft-stuttgart.de> Date: Fri, 7 May 2021 16:49:57 +0200 Subject: [PATCH] update if conditions --- functions/methods.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/functions/methods.js b/functions/methods.js index 316acec0..0037a7e1 100644 --- a/functions/methods.js +++ b/functions/methods.js @@ -68,7 +68,10 @@ var methods = { getUserByEmail: async function(email) { try { let rows = await dbconn.user.promise().query('SELECT id, verificationStatus, salutation, title, firstname, lastname, industry, organisation, speciality, m4lab_idp FROM user WHERE email = "' +email+'"') - return rows[0][0] + if (rows[0][0]) { + return rows[0][0] + } + else { return null } } catch (err) { console.error(err) } @@ -77,7 +80,7 @@ var methods = { getUserEmailById: async function(userId) { try { let rows = await dbconn.user.promise().query('SELECT email FROM user WHERE id = ' +userId) - if (rows[0]) { + if (rows[0][0]) { return rows[0][0].email } else { return null } @@ -89,7 +92,7 @@ var methods = { checkUserEmail: async function(email) { try { let rows = await dbconn.user.promise().query('SELECT id, email FROM user WHERE email = "' +email+'"') - if (rows[0]) { + if (rows[0][0]) { return rows[0][0] } else { return null } @@ -102,7 +105,7 @@ var methods = { try { let rows = await dbconn.user.promise().query('SELECT t1.user_id, t2.email FROM userdb.credential AS t1 INNER JOIN userdb.user AS t2 ON t1.user_id = t2.id AND t1.resetPasswordToken = "' +token+'" and resetPasswordExpires > '+Date.now()) - if (rows[0]) { + if (rows[0][0]) { return rows[0][0] } else { return null } @@ -152,7 +155,7 @@ var methods = { getVerificationTokenByUserId: async function(userId) { try { let rows = await dbconn.user.promise().query('SELECT token FROM verification WHERE user_id = "' +userId+'"') - if (rows[0]) { + if (rows[0][0]) { return rows[0][0].token } else { return null } @@ -164,7 +167,7 @@ var methods = { getUserIdByVerificationToken: async function(token) { try { let rows = await dbconn.user.promise().query('SELECT user_id FROM verification WHERE token = "' +token+'"') - if (rows[0]) { + if (rows[0][0]) { return rows[0][0].user_id } else { -- GitLab