"E-Mail-Adresse", "password" => "Passwort", "password_repeat" => "Passwort wiederholen", "old_password" => "Altes Passwort" ); public function __construct($view) { $this->db = new AuthModel(); $this->view = $view; } public function showAuthForm() { $this->view->setVars([ 'labels' => $this->labels, 'validData' => $this->validData, 'errors' => $this->errors ]); } public function showConfirmation($message = "Aktion erfolgreich.") { $this->view->setVars(['message' => $message]); $this->view->render('auth/confirmation'); } public function validateForm() { foreach ($this->labels as $index => $value) { if (!isset($_POST[$index]) || empty($_POST[$index])) { $this->errors[$index] = "Bitte " . $value . " angeben"; } else { $this->validData[$index] = trim($_POST[$index]); } } if (!empty($this->errors)) { $this->view->setDoMethodName("showAuthForm"); $this->showAuthForm(); } else { $this->view->setDoMethodName("showConfirmation"); $this->showConfirmation(); } } public function login() { $email = $_POST['email'] ?? ''; $password = $_POST['password'] ?? ''; if (empty($email) || empty($password)) { $this->errors['login'] = "Bitte E-Mail und Passwort eingeben."; return $this->showAuthForm(); } $result = $this->db->login($email, $password); if ($result === true) { $_SESSION['user'] = $email; $this->showConfirmation("Login erfolgreich."); } elseif (is_string($result)) { $this->errors['login'] = $result; $this->showAuthForm(); } else { $this->errors['login'] = "Login fehlgeschlagen."; $this->showAuthForm(); } } public function register() { $data = [ 'email' => $_POST['email'] ?? '', 'password' => $_POST['password'] ?? '', 'password_repeat' => $_POST['password_repeat'] ?? '', 'straße' => $_POST['straße'] ?? '', 'hausnr' => $_POST['hausnr'] ?? '', 'ort' => $_POST['ort'] ?? '', 'postleitzahl' => $_POST['postleitzahl'] ?? '', 'land' => $_POST['land'] ?? '', 'vorname' => $_POST['vorname'] ?? '', 'nachname' => $_POST['nachname'] ?? '', 'tel' => $_POST['tel'] ?? '' ]; if (!$this->db->checkDoublePw($data['password'], $data['password_repeat'])) { $this->errors['password'] = "Passwörter stimmen nicht überein."; return $this->showAuthForm(); } $result = $this->db->register( $data['email'], $data['password'], $data['straße'], $data['hausnr'], $data['ort'], $data['postleitzahl'], $data['land'], $data['vorname'], $data['nachname'], $data['tel'] ); if ($result === true) { $this->showConfirmation("Registrierung erfolgreich."); } elseif (is_string($result)) { $this->errors['register'] = $result; $this->showAuthForm(); } else { $this->errors['register'] = "Registrierung fehlgeschlagen."; $this->showAuthForm(); } } public function forgotPassword() { $email = $_POST['email'] ?? ''; if (empty($email)) { $this->errors['email'] = "Bitte E-Mail-Adresse angeben."; return $this->showAuthForm(); } $this->db->pwForgot($email); $this->showConfirmation("Ein temporäres Passwort wurde an Ihre E-Mail gesendet."); } public function changePassword() { $email = $_POST['email'] ?? ''; $oldpw = $_POST['old_password'] ?? ''; $newpw = $_POST['password'] ?? ''; $repeat = $_POST['password_repeat'] ?? ''; if (!$this->db->checkDoublePw($newpw, $repeat)) { $this->errors['password'] = "Neue Passwörter stimmen nicht überein."; return $this->showAuthForm(); } $result = $this->db->updatePassword($email, $oldpw, $newpw); if ($result === true) { $this->showConfirmation("Passwort erfolgreich geändert."); } elseif (is_string($result)) { $this->errors['password'] = $result; $this->showAuthForm(); } else { $this->errors['password'] = "Fehler beim Aktualisieren des Passworts."; $this->showAuthForm(); } } }