diff --git a/php/controller/register-controller.php b/php/controller/register-controller.php index 293c099..a4d2feb 100644 --- a/php/controller/register-controller.php +++ b/php/controller/register-controller.php @@ -1,63 +1,43 @@ - -
-
+require_once "php/model/LocalUserDAO.php"; +require_once "php/validator/user-validator.php"; -

Jetzt Registrieren!

+$error = null; - -

- -

- +if ($_SERVER["REQUEST_METHOD"] === "POST") { -
+ $email = trim($_POST["email"] ?? ""); + $vorname = trim($_POST["vorname"] ?? ""); + $nachname = trim($_POST["nachname"] ?? ""); + $plainPassword = $_POST["password"] ?? ""; -

Email:

- " - required> + if (!userEmailValidator($email)) { + $error = "Bitte gib eine gültige E-Mail-Adresse ein."; + } elseif (!userNameValidator($vorname)) { + $error = "Der Vorname muss 2 bis 50 Zeichen lang sein und darf nur Buchstaben, Umlaute, Leerzeichen und Bindestriche enthalten."; + } elseif (!userNameValidator($nachname)) { + $error = "Der Nachname muss 2 bis 50 Zeichen lang sein und darf nur Buchstaben, Umlaute, Leerzeichen und Bindestriche enthalten."; + } elseif (!userPasswordValidator($plainPassword)) { + $error = "Das Passwort muss 8 bis 72 Zeichen lang sein."; + } else { + try { + $dao = new LocalUserDAO(); -

Vorname:

- " - required> + $password = password_hash($plainPassword, PASSWORD_DEFAULT); -

Nachname:

- " - required> + $dao->addUser($email, $vorname, $nachname, $password); -

Passwort:

- + $_SESSION["user"] = $vorname . " " . $nachname; + $_SESSION["user_email"] = $email; - + header("Location: index.php"); + exit(); -
- -
-
\ No newline at end of file + } catch (InvalidArgumentException $e) { + $error = $e->getMessage(); + } catch (Exception $e) { + $error = "Die Registrierung konnte nicht gespeichert werden."; + } + } +} \ No newline at end of file diff --git a/php/validator/user-validator.php b/php/validator/user-validator.php index 96db1ce..80dd996 100644 --- a/php/validator/user-validator.php +++ b/php/validator/user-validator.php @@ -1,71 +1,28 @@ = 8 && $zeichenAnzahl <= 72) { - return true; - } else { - return false; - } + return $zeichenAnzahl >= 8 && $zeichenAnzahl <= 72; } -/** - * Prüft ein optionales Passwort. - * Leeres Passwort ist erlaubt, wenn der Nutzer sein Passwort nicht ändern möchte. - * Wenn ein Passwort eingegeben wurde, gelten die normalen Passwortregeln. - * - * @param $password - * @return bool - */ function userOptionalPasswordValidator($password) { if (!isset($password) || $password === '') { @@ -73,6 +30,4 @@ function userOptionalPasswordValidator($password) } return userPasswordValidator($password); -} - -?> \ No newline at end of file +} \ No newline at end of file