refactor: Validierungslogik ins Model verschoben
- pwRequirementCheck und checkDoublePw aus Controller ins Model - Alle Passwort- und E-Mail-Validierungen jetzt zentral im Model - Controller macht nur noch Request/Response Handling - Saubere MVC-Trennung
This commit is contained in:
@@ -71,9 +71,9 @@ class AuthController
|
||||
$data = [
|
||||
'vorname' => $_POST['vorname'] ?? '',
|
||||
'nachname' => $_POST['nachname'] ?? '',
|
||||
'straße' => $_POST['straße'] ?? '',
|
||||
'straße' => $_POST['strasse'] ?? '',
|
||||
'hausnr' => $_POST['hausnr'] ?? '',
|
||||
'postleitzahl' => $_POST['postleitzahl'] ?? '',
|
||||
'plz' => $_POST['plz'] ?? '',
|
||||
'ort' => $_POST['ort'] ?? '',
|
||||
'land' => $_POST['land'] ?? '',
|
||||
'tel' => $_POST['tel'] ?? '',
|
||||
@@ -83,52 +83,18 @@ class AuthController
|
||||
'isAdmin' => $_POST['isAdmin'] ?? false,
|
||||
];
|
||||
|
||||
$errors = [];
|
||||
$result = $this->model->register($data);
|
||||
|
||||
if (!$this->model->checkDoublePw($data['password'], $data['password_repeat'])) {
|
||||
$errors['password'] = "Passwörter stimmen nicht überein.";
|
||||
if ($result === true) {
|
||||
$this->view->setVars(['success' => 'Registrierung erfolgreich!']);
|
||||
$this->view->render('Auth/showAuthForm');
|
||||
exit;
|
||||
} else {
|
||||
$errors['register'] = is_string($result) ? $result : "Registrierung fehlgeschlagen.";
|
||||
$this->view->setVars(['errors' => $errors, 'validData' => $data]);
|
||||
$this->view->render('Auth/showRegistrationForm');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($this->pwRequirementCheck($data['password'])) {
|
||||
$errors['password'] = "Passwort muss mindestens 8 Zeichen lang sein und mindestens ein Großbuchstabe, ein Kleinbuchstabe, eine Zahl und ein Sonderzeichen enthalten.";
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
$result = $this->model->register($data);
|
||||
|
||||
if ($result === true) {
|
||||
$this->view->setVars([
|
||||
'success' => "Registrierung war erfolgreich."
|
||||
]);
|
||||
} else {
|
||||
$errors['register'] = is_string($result) ? $result : "Registrierung fehlgeschlagen.";
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->setVars([
|
||||
'errors' => $errors,
|
||||
'validData' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
private function pwRequirementCheck($password){
|
||||
$error = [];
|
||||
|
||||
if(strlen($password) <= 8)
|
||||
$error[] = "min 8 Charackter";
|
||||
if(!preg_match("/[A-Z]/", $password))
|
||||
$error[] = "min one large Character";
|
||||
if(!preg_match("/[a-z]/", $password))
|
||||
$error[] = "min one small charakter";
|
||||
if(!preg_match("/[0-9]/", $password))
|
||||
$error[] = "min one number";
|
||||
if(!preg_match("[^a-zA-Z0-9\s]", $password));
|
||||
$error[] = "min one special character";
|
||||
|
||||
if(empty($error))
|
||||
return true;
|
||||
else
|
||||
return $error;
|
||||
}
|
||||
|
||||
public function forgotPassword() {
|
||||
|
Reference in New Issue
Block a user