Skip to content

Commit

Permalink
User Admin: fixed unique username check when values already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
SKuipers committed Feb 5, 2025
1 parent 2b099a1 commit 75328d8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------
Expand Down
6 changes: 3 additions & 3 deletions publicRegistrationCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?? '';
Expand All @@ -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);
}
4 changes: 2 additions & 2 deletions src/Forms/Input/TextField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'),
Expand All @@ -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;
Expand Down

0 comments on commit 75328d8

Please sign in to comment.