From 824e92b21e1ea78a5e37535d7111d0b9126660cb Mon Sep 17 00:00:00 2001 From: aydreeihn <adriane@enhancesoft.com> Date: Tue, 19 Jun 2018 14:46:59 -0500 Subject: [PATCH] User Registration Fixes: This commit fixes a bug where Public User Registration always resulted in creating a new User. Now, if a User goes to register an Account and their email already matches a User in the system, we will register the existing User. To set the registration method, go to: Admin Panel | Settings | Users | Registration Method --- account.php | 7 +++---- include/class.user.php | 10 ++-------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/account.php b/account.php index 18231ab48..416cd4761 100644 --- a/account.php +++ b/account.php @@ -52,7 +52,6 @@ if ($user && $_POST) { if (!$errors && $user->updateInfo($_POST, $errors)) Http::redirect('tickets.php'); } - elseif ($_POST) { $user_form = UserForm::getUserForm()->getForm($_POST); if ($thisclient) { @@ -81,12 +80,12 @@ elseif ($_POST) { $errors['email'] = sprintf(__('%s is a required field'), $user_form->getField('email')->getLocal('label')); elseif (!$user_form->getField('name')->getClean()) $errors['name'] = sprintf(__('%s is a required field'), $user_form->getField('name')->getLocal('label')); + // Registration for existing users + elseif ($addr && !($user = User::lookupByEmail($addr))) + $errors['err'] = __('Unable to register account. See messages below'); // Users created from ClientCreateRequest elseif (isset($_POST['backend']) && !($user = User::fromVars($user_form->getClean()))) $errors['err'] = __('Unable to create local account. See messages below'); - // Registration for existing users - elseif (!$user && !$thisclient && !($user = User::fromVars($user_form->getClean()))) - $errors['err'] = __('Unable to register account. See messages below'); // New users and users registering from a ticket access link elseif (!$user && !($user = $thisclient ?: User::fromForm($user_form))) $errors['err'] = __('Unable to register account. See messages below'); diff --git a/include/class.user.php b/include/class.user.php index 083e0d5bf..71a5289a8 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -1147,16 +1147,10 @@ class UserAccount extends VerySimpleModel { } /* - * This assumes the staff is doing the update + * Updates may be done by Staff or by the User if registration + * options are set to Public */ function update($vars, &$errors) { - global $thisstaff; - - - if (!$thisstaff) { - $errors['err'] = __('Access denied'); - return false; - } // TODO: Make sure the username is unique -- GitLab