From 45d4daf0f36f9d20aa316c9eea634c0f3cd9243f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Wegener?= Date: Thu, 5 Dec 2019 02:00:48 +0100 Subject: [PATCH] Check for falsy existingUser variable. Fixes #1369 Use another return code for "User already exist" This allows external scripts differentiating between "failure" and "everything is fine" Co-Authored-By: Max Wu Signed-off-by: Soeren Wegener --- bin/manage_users | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/manage_users b/bin/manage_users index 0acbeeb1..113352a3 100755 --- a/bin/manage_users +++ b/bin/manage_users @@ -37,9 +37,9 @@ function getPass (argv, action) { async function createUser (argv) { const existingUser = await models.User.findOne({ where: { email: argv['add'] } }) // Cannot create already-existing users - if (existingUser !== undefined) { + if (existingUser) { console.log(`User with e-mail ${existingUser.email} already exists! Aborting ...`) - process.exit(1) + process.exit(2) } const pass = getPass(argv, 'add') @@ -56,7 +56,7 @@ async function createUser (argv) { async function deleteUser (argv) { // Cannot delete non-existing users const existingUser = await models.User.findOne({ where: { email: argv['del'] } }) - if (existingUser === undefined) { + if (!existingUser) { console.log(`User with e-mail ${argv['del']} does not exist, cannot delete`) process.exit(1) } @@ -71,7 +71,7 @@ async function deleteUser (argv) { async function resetUser (argv) { const existingUser = await models.User.findOne({ where: { email: argv['reset'] } }) // Cannot reset non-existing users - if (existingUser === undefined) { + if (!existingUser) { console.log(`User with e-mail ${argv['reset']} does not exist, cannot reset`) process.exit(1) }