Änderungen von templates und Hinzufügen von Validation
This commit is contained in:
parent
1204c89ca3
commit
e659535923
@ -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;
|
||||
}
|
@ -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(){
|
||||
|
@ -29,6 +29,7 @@ foreach ($labels as $key => $value) {
|
||||
|
||||
<input type="hidden" name="controller" value="admin">
|
||||
<input type="hidden" name="do" value="showForm">
|
||||
<input type="submit" name="submit" value="Absenden"></form>
|
||||
<button type="submit" class="btn">Absenden</button>
|
||||
|
||||
|
||||
<?php include dirname(__DIR__).'/footer.phtml'; ?>
|
@ -4,17 +4,32 @@
|
||||
|
||||
<h1>Als Benutzer anmelden</h1>
|
||||
|
||||
<form method="post">
|
||||
<form method="post" class="form-grid">
|
||||
|
||||
<label for="reg_email">Email:</label>
|
||||
<input type="email" name="email" id="reg_email" required>
|
||||
<?php foreach ($labels as $key => $label): ?>
|
||||
<div class="input">
|
||||
<label for="reg_<?= $key ?>"><?= $label ?></label>
|
||||
<?php if ($key === 'password'): ?>
|
||||
<input type="password" name="<?= $key ?>" id="reg_<?= $key ?>" required>
|
||||
<?php elseif($key === 'email'): ?>
|
||||
<input type="email" name="<?= $key ?>" id="reg_<?= $key ?>" required>
|
||||
<?php else: ?>
|
||||
<input type="text" name="<?= $key ?>" id="reg_<?= $key ?>" value="<?= htmlspecialchars($validData[$key] ?? '') ?>" required>
|
||||
<?php endif; ?>
|
||||
|
||||
<label for="reg_password">Passwort:</label>
|
||||
<input type="password" name="password" id="reg_password" required>
|
||||
<?php if (!empty($errors[$key])): ?>
|
||||
<div class="error"><?= $errors[$key] ?></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
|
||||
|
||||
<input type="hidden" name="controller" value="user">
|
||||
<input type="hidden" name="do" value="login">
|
||||
<button type="submit" class="btn" style="display: block">Login</button>
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
|
@ -4,35 +4,33 @@
|
||||
|
||||
<h1>Benutzer erstellen</h1>
|
||||
|
||||
<form method="post">
|
||||
<h2>Registrieren</h2>
|
||||
<form method="post" class="form-grid">
|
||||
|
||||
<label for="reg_name">Vorname:</label>
|
||||
<input type="text" name="name" id="reg_name" required>
|
||||
<?php foreach ($labels as $key => $label): ?>
|
||||
<div class="input">
|
||||
<label for="reg_<?= $key ?>"><?= $label ?></label>
|
||||
<?php if ($key === 'password'): ?>
|
||||
<input type="password" name="<?= $key ?>" id="reg_<?= $key ?>" required>
|
||||
<?php elseif ($key === 'role'): ?>
|
||||
<label><input type="radio" name="role" value="user" <?= (isset($validData['role']) && $validData['role'] === 'user') ? 'checked' : '' ?>> User</label>
|
||||
<label><input type="radio" name="role" value="leiter" <?= (isset($validData['role']) && $validData['role'] === 'leiter') ? 'checked' : '' ?>> Leiter</label>
|
||||
<?php else: ?>
|
||||
<input type="text" name="<?= $key ?>" id="reg_<?= $key ?>" value="<?= htmlspecialchars($validData[$key] ?? '') ?>" required>
|
||||
<?php endif; ?>
|
||||
|
||||
<label for="reg_lastname">Nachname:</label>
|
||||
<input type="text" name="lastname" id="reg_lastname" required>
|
||||
<?php if (!empty($errors[$key])): ?>
|
||||
<div class="error"><?= $errors[$key] ?></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<label for="reg_email">Email:</label>
|
||||
<input type="email" name="email" id="reg_email" required>
|
||||
|
||||
<label for="reg_password">Passwort:</label>
|
||||
<input type="password" name="password" id="reg_password" required>
|
||||
|
||||
<p>Wähle deine Rolle:</p>
|
||||
<label>
|
||||
<input type="radio" name="role" value="user" required> User
|
||||
</label>
|
||||
<label>
|
||||
<input type="radio" name="role" value="leiter"> Leiter
|
||||
</label>
|
||||
|
||||
<input type="hidden" name="controller" value="user">
|
||||
<input type="hidden" name="do" value="register">
|
||||
<button type="submit" class="btn" style="display: block">Registrieren</button>
|
||||
|
||||
<button type="submit" class="btn">Registrieren</button>
|
||||
</form>
|
||||
|
||||
<a href="?controller=User&do=showUserLoginForm">Haben Sie schon ein Benutzer Konto?</a>
|
||||
|
||||
|
||||
<?php
|
||||
include dirname(__DIR__).'/footer.phtml';
|
||||
|
@ -20,7 +20,10 @@
|
||||
<h3 class="logo">bib<span>course</span></h3>
|
||||
<div id="metanavi">
|
||||
<a class="btn btn-user" href="?controller=Admin&do=showForm"><span class="material-icons">person</span></a>
|
||||
<a class="btn btn-register" href="?controller=User&do=showUserRegisterForm">Registration</a>
|
||||
<div class="buttons-container">
|
||||
<a class="btn btn-login" href="?controller=User&do=showUserLoginForm">Anmeldung</a>
|
||||
<a class="btn btn-register" href="?controller=User&do=showUserRegisterForm">Registration</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<nav>
|
||||
|
Loading…
x
Reference in New Issue
Block a user