Änderungen von templates und Hinzufügen von Validation
This commit is contained in:
@@ -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(){
|
||||
|
Reference in New Issue
Block a user