From 75328d866ecf5308ef7a7cca7222369e353dedda Mon Sep 17 00:00:00 2001 From: Sandra Kuipers Date: Wed, 5 Feb 2025 13:34:55 +0800 Subject: [PATCH] User Admin: fixed unique username check when values already exist --- CHANGELOG.txt | 1 + publicRegistrationCheck.php | 6 +++--- src/Forms/Input/TextField.php | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 431e805be2..e6d2e1ba5d 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -47,6 +47,7 @@ v29.0.00 System Admin: fixed field validation for Student Default Email in Form Builder System Admin: fixed uniqueness check when editing a page in Form Builder Timetable Admin: fixed support staff not editable in Course Enrolment by Person + User Admin: fixed unique username check when values already exist v28.0.01 -------- diff --git a/publicRegistrationCheck.php b/publicRegistrationCheck.php index 84041c0467..0b618e42e9 100644 --- a/publicRegistrationCheck.php +++ b/publicRegistrationCheck.php @@ -27,10 +27,10 @@ $currentUsername = $_POST['currentUsername'] ?? ''; if (!empty($currentUsername) && $currentUsername == $username) { - echo '0'; + die('0'); } else if (!empty($username)) { $generator = new UsernameGenerator($pdo); - echo $generator->isUsernameUnique($username)? '0' : '1'; + die($generator->isUsernameUnique($username)? '0' : '1'); } $email = $_POST['email'] ?? ''; @@ -40,5 +40,5 @@ $sql = "SELECT COUNT(*) FROM gibbonPerson WHERE email=:email"; $result = $pdo->executeQuery($data, $sql); - echo ($result && $result->rowCount() == 1)? $result->fetchColumn(0) : -1; + die(($result && $result->rowCount() == 1)? $result->fetchColumn(0) : -1); } diff --git a/src/Forms/Input/TextField.php b/src/Forms/Input/TextField.php index d4e44d965a..ad7b2d2217 100644 --- a/src/Forms/Input/TextField.php +++ b/src/Forms/Input/TextField.php @@ -123,10 +123,9 @@ public function uniqueField($ajaxURL, $data = []) $label = $this->row->getElement('label'.$this->getName()); $fieldLabel = (!empty($label))? $label->getLabelText() : ucfirst($this->getName()); + $data = array_replace(array('fieldName' => $this->getName()), $data); $this->unique = [ - 'ajaxURL' => $ajaxURL, - 'ajaxData' => array_replace(array('fieldName' => $this->getName()), $data), 'alertSuccess' => sprintf(__('%1$s available'), $fieldLabel), 'alertFailure' => sprintf(__('%1$s already in use'), $fieldLabel), 'alertError' => __('An error has occurred.'), @@ -135,6 +134,7 @@ public function uniqueField($ajaxURL, $data = []) $this->setAttribute('x-model', "uniqueValue"); $this->setAttribute('hx-post', $ajaxURL); $this->setAttribute('hx-trigger', 'input delay:300ms'); + $this->setAttribute('hx-vals', json_encode($data)); $this->setAttribute('x-on:htmx:after-request.camel', 'unique = $event.detail.xhr.responseText <= 0;'); return $this;