Skip to content

Commit

Permalink
refactor check unique fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Pathologic committed Feb 19, 2021
1 parent 0f54257 commit 516393b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/modUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public function save($fire_events = false, $clearCache = false)
return false;
}

if ($this->isChanged('username') && !$this->checkUnique('users', 'username')) {
if ($this->isChanged('username') && !$this->isUnique('username')) {
$this->log['UniqueUsername'] = 'username not unique <pre>' . print_r(
$this->get('username'),
true
Expand All @@ -404,7 +404,7 @@ public function save($fire_events = false, $clearCache = false)
return false;
}

if ($this->isChanged('username') && !$this->checkUnique('user_attributes', 'email', 'internalKey')) {
if ($this->isChanged('email') && !$this->isUnique('email')) {
$this->log['UniqueEmail'] = 'Email not unique <pre>' . print_r($this->get('email'), true) . '</pre>';

return false;
Expand Down Expand Up @@ -468,6 +468,21 @@ public function save($fire_events = false, $clearCache = false)
return $this->id;
}

/**
* @param $field
* @return bool
*/
public function isUnique($field) {
$out = false;
if (isset($this->default_field['user'][$field])) {
$out = $this->checkUnique('users', $field);
} elseif(isset($this->default_field['user'][$field])) {
$out = $this->checkUnique('user_attributes', $field, 'primaryKey');
}

return $out;
}

/**
* @param array $fld
*/
Expand Down

0 comments on commit 516393b

Please sign in to comment.