Register und login gefixt

This commit is contained in:
2025-06-30 09:56:52 +02:00
parent 36d6364cd0
commit ce23d839a3
4 changed files with 198 additions and 100 deletions

View File

@@ -32,23 +32,28 @@ class AuthController
}
public function login() {
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
$email = $_POST['email'];
$password = $_POST['password'];
$result = $this->model->login($email, $password);
if ($result === true) {
$_SESSION['user'] = $email;
$this->view->setVars([
'loginSuccess' => true,
'email' => $email
]);
} else {
$this->view->setVars([
'errors' => ['login' => is_string($result) ? $result : "Login fehlgeschlagen."],
'validData' => ['email' => $email]
'validData' => ['email' => $email],
'loginSuccess' => false
]);
}
}
public function register() {
$data = [
'vorname' => $_POST['vorname'] ?? '',
'nachname' => $_POST['nachname'] ?? '',
@@ -64,31 +69,55 @@ class AuthController
'isAdmin' => $_POST['isAdmin'] ?? false,
];
// Passwortabgleich prüfen
$errors = [];
if (!$this->model->checkDoublePw($data['password'], $data['password_repeat'])) {
$_SESSION['auth_errors']['password'] = "Passwörter stimmen nicht überein.";
$_SESSION['auth_validData'] = $data;
$errors['password'] = "Passwörter stimmen nicht überein.";
}
$result = $this->model->register(
$data['email'], $data['password'], $data['straße'], $data['hausnr'],
$data['ort'], $data['postleitzahl'], $data['land'],
$data['vorname'], $data['nachname'], $data['tel'], $data['isAdmin']
);
if ($result === true) {
//header("Location: /?controller=Auth&do=showConfirmation&msg=register");
exit;
} else {
$_SESSION['auth_errors']['register'] = is_string($result) ? $result : "Registrierung fehlgeschlagen.";
$_SESSION['auth_validData'] = $data;
//header("Location: /?controller=Auth&do=showAuthForm");
//exit;
if ($this->pwRequirementCheck($data['password'])) {
$errors
}
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
]);
}
public function forgotPassword()
{
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() {
$email = $_POST['email'] ?? '';
if (empty($email)) {
$_SESSION['auth_errors']['email'] = "Bitte E-Mail-Adresse angeben.";