Skip to content

Commit

Permalink
Fix member creation
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed May 8, 2024
1 parent 95bbbc2 commit 7971106
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions galette/lib/Galette/Entity/Adherent.php
Expand Up @@ -1219,25 +1219,20 @@ public function check(array $values, array $required, array $disabled): bool|arr
if ($value !== null && $value !== true && $value !== false && !is_object($value)) {
$value = stripslashes($value);
}
$this->$prop = $value;

// now, check validity
if ($value !== null && $value != '') {
if ($key !== 'mdp_adh') {
$this->validate($key, $value, $values);
}
} elseif (empty($this->id)) {
//ensure login and password are not empty
if (($key == 'login_adh' || $key == 'mdp_adh') && !isset($required[$key])) {
if ($key !== 'mdp_adh') { //mdp_adh is handled after all data has been set
if (empty($this->id) && empty($value) && ($key == 'login_adh' || $key == 'mdp_adh') && !isset($required[$key])) {
$p = new Password($this->zdb);
$generated_value = $p->makeRandomPassword(15);
if ($key == 'login_adh') {
//'@' is not permitted in logins
$this->$prop = str_replace('@', 'a', $generated_value);
$value = str_replace('@', 'a', $generated_value);
} else {
$this->$prop = $generated_value;
$value = $generated_value;
}
}
$this->validate($key, $value, $values);
}
}
}
Expand Down Expand Up @@ -1330,6 +1325,10 @@ public function validate(string $field, mixed $value, array $values): void

if ($value === null || (is_string($value) && trim($value) == '')) {
//empty values are OK
if ($field == 'parent_id') {
//parent_id cannot be a string
$value = null;
}
$this->$prop = $value;
return;
}
Expand Down Expand Up @@ -1398,6 +1397,7 @@ public function validate(string $field, mixed $value, array $values): void
}
break;
case 'email_adh':
$this->$prop = $value;
if (!GaletteMail::isValidEmail($value)) {
$this->errors[] = _T("- Non-valid E-Mail address!") .
' (' . $this->getFieldLabel($field) . ')';
Expand Down Expand Up @@ -1428,6 +1428,7 @@ public function validate(string $field, mixed $value, array $values): void
}
break;
case 'login_adh':
$this->$prop = $value;
/** FIXME: add a preference for login length */
if (strlen($value) < 2) {
$this->errors[] = str_replace(
Expand Down Expand Up @@ -1544,6 +1545,9 @@ public function validate(string $field, mixed $value, array $values): void
$this->loadParent();
}
break;
default:
$this->$prop = $value;
break;
}
}

Expand Down

0 comments on commit 7971106

Please sign in to comment.