Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix member creation #501

Merged
merged 1 commit into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions galette/lib/Galette/Entity/Adherent.php
Original file line number Diff line number Diff line change
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
Loading