From e6595359239025578e068adf7956fb6b48807adc Mon Sep 17 00:00:00 2001 From: Illia Hromovoi Date: Wed, 25 Jun 2025 10:55:39 +0200 Subject: [PATCH] =?UTF-8?q?=C3=84nderungen=20von=20templates=20und=20Hinzu?= =?UTF-8?q?f=C3=BCgen=20von=20Validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CSS/Element/button.css | 11 +++++ Controller/UserController.php | 59 ++++++++++++++++++++++++++- Views/Admin/showForm.phtml | 3 +- Views/User/showUserLoginForm.phtml | 25 +++++++++--- Views/User/showUserRegisterForm.phtml | 42 +++++++++---------- Views/header.phtml | 5 ++- 6 files changed, 115 insertions(+), 30 deletions(-) diff --git a/CSS/Element/button.css b/CSS/Element/button.css index 8df442c..5b83ca3 100644 --- a/CSS/Element/button.css +++ b/CSS/Element/button.css @@ -1,3 +1,10 @@ +.buttons-container{ + display: flex; + justify-content: space-between; + align-items: center; + gap: 10px; +} + .btn{ background: var(--brand-primary); color: var(--brand-white); @@ -21,6 +28,10 @@ aspect-ratio: 1/1; } +.btn-login{ + background-color: transparent; +} + .btn-user > span { font-size: 28px; } \ No newline at end of file diff --git a/Controller/UserController.php b/Controller/UserController.php index a58a4fc..4205514 100644 --- a/Controller/UserController.php +++ b/Controller/UserController.php @@ -10,13 +10,32 @@ class UserController{ private $validData = array(); private $errors = array(); + private $labels = [ + "name" => "Vorname*", + "lastname" => "Nachname*", + "email" => "E-Mail*", + "password" => "Passwort*", + "role" => "Rolle*" + ]; + + private $validLoginData = array(); + private $loginErrors = array(); + private $loginLabels = [ + "email" => "E-Mail*", + "password" => "Passwort*", + ]; + public function __construct($view){ $this->db = new UserModel(); $this->view = $view; } public function showUserRegisterForm(){ - + $this->view->setVars([ + 'labels' => $this->labels, + 'errors' => $this->errors, + 'validData' => $this->validData + ]); } public function showUserRegisterConfirmation(){ @@ -24,7 +43,45 @@ class UserController{ } public function showUserLoginForm(){ + $this->view->setVars([ + 'labels' => $this->loginLabels, + 'errors' => $this->loginErrors, + 'validData' => $this->validLoginData + ]); + } + private function validateForm() { + foreach ($this->labels as $key => $label) { + if (!isset($_POST[$key]) || trim($_POST[$key]) === '') { + $this->errors[$key] = "Bitte $label angeben"; + } else { + $this->validData[$key] = trim($_POST[$key]); + } + } + + if (isset($this->validData['password'])) { + if (strlen($this->validData['password']) < 6) { + $this->errors['password'] = "Das Passwort muss mindestens 6 Zeichen lang sein."; + } + } + + if (isset($this->validData['email']) && !filter_var($this->validData['email'], FILTER_VALIDATE_EMAIL)) { + $this->errors['email'] = "Bitte eine gültige E-Mail-Adresse eingeben."; + } + } + + public function validateLoginForm(){ + foreach ($this->loginLabels as $key => $label) { + if (isset($this->validData['password'])) { + if (strlen($this->validData['password']) < 6) { + $this->errors['password'] = "Das Passwort muss mindestens 6 Zeichen lang sein."; + } + } + + if (isset($this->validData['email']) && !filter_var($this->validData['email'], FILTER_VALIDATE_EMAIL)) { + $this->errors['email'] = "Bitte eine gültige E-Mail-Adresse eingeben."; + } + } } public function showUserLoginConfirmation(){ diff --git a/Views/Admin/showForm.phtml b/Views/Admin/showForm.phtml index 2b7b1db..e66b63a 100644 --- a/Views/Admin/showForm.phtml +++ b/Views/Admin/showForm.phtml @@ -29,6 +29,7 @@ foreach ($labels as $key => $value) { - + + \ No newline at end of file diff --git a/Views/User/showUserLoginForm.phtml b/Views/User/showUserLoginForm.phtml index e541dbf..af1cff4 100644 --- a/Views/User/showUserLoginForm.phtml +++ b/Views/User/showUserLoginForm.phtml @@ -4,17 +4,32 @@

Als Benutzer anmelden

-
+ - - + $label): ?> +
+ + + + + + + + - - + +
+ +
+ + + + +
diff --git a/Views/User/showUserRegisterForm.phtml b/Views/User/showUserRegisterForm.phtml index 2ca254c..00c5175 100644 --- a/Views/User/showUserRegisterForm.phtml +++ b/Views/User/showUserRegisterForm.phtml @@ -4,35 +4,33 @@

Benutzer erstellen

-
-

Registrieren

+ - - + $label): ?> +
+ + + + + + + + + - - + +
+ +
+ - - - - - - -

Wähle deine Rolle:

- - - - + +
-Haben Sie schon ein Benutzer Konto? + bibcourse
person - Registration +