Reviewnacharbeitung
This commit is contained in:
@@ -1,63 +1,43 @@
|
||||
<?php
|
||||
$error = $error ?? null;
|
||||
?>
|
||||
|
||||
<!--
|
||||
Form: Registrierung
|
||||
Funktion: Erstellung neuer Benutzerkonten
|
||||
-->
|
||||
<main class="login-page">
|
||||
<div class="login-container">
|
||||
require_once "php/model/LocalUserDAO.php";
|
||||
require_once "php/validator/user-validator.php";
|
||||
|
||||
<h1>Jetzt Registrieren!</h1>
|
||||
$error = null;
|
||||
|
||||
<?php if (!empty($error)): ?>
|
||||
<p class="alert-message is-error">
|
||||
<?php echo htmlspecialchars($error); ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
|
||||
<form method="post" action="index.php?pfad=register">
|
||||
$email = trim($_POST["email"] ?? "");
|
||||
$vorname = trim($_POST["vorname"] ?? "");
|
||||
$nachname = trim($_POST["nachname"] ?? "");
|
||||
$plainPassword = $_POST["password"] ?? "";
|
||||
|
||||
<p class="input-label">Email:</p>
|
||||
<input type="email"
|
||||
name="email"
|
||||
class="login-input"
|
||||
placeholder="mustermann@web.de"
|
||||
value="<?php echo htmlspecialchars($_POST["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();
|
||||
|
||||
<p class="input-label">Vorname:</p>
|
||||
<input type="text"
|
||||
name="vorname"
|
||||
class="login-input"
|
||||
placeholder="Max"
|
||||
value="<?php echo htmlspecialchars($_POST["vorname"] ?? ""); ?>"
|
||||
required>
|
||||
$password = password_hash($plainPassword, PASSWORD_DEFAULT);
|
||||
|
||||
<p class="input-label">Nachname:</p>
|
||||
<input type="text"
|
||||
name="nachname"
|
||||
class="login-input"
|
||||
placeholder="Mustermann"
|
||||
value="<?php echo htmlspecialchars($_POST["nachname"] ?? ""); ?>"
|
||||
required>
|
||||
$dao->addUser($email, $vorname, $nachname, $password);
|
||||
|
||||
<p class="input-label">Passwort:</p>
|
||||
<input type="password"
|
||||
name="password"
|
||||
class="login-input"
|
||||
placeholder="Passwort"
|
||||
required>
|
||||
$_SESSION["user"] = $vorname . " " . $nachname;
|
||||
$_SESSION["user_email"] = $email;
|
||||
|
||||
<button type="submit"
|
||||
value="register"
|
||||
name="registerSubmit"
|
||||
class="login-button">
|
||||
kostenlos registrieren
|
||||
</button>
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$error = $e->getMessage();
|
||||
} catch (Exception $e) {
|
||||
$error = "Die Registrierung konnte nicht gespeichert werden.";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,71 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Prüft, ob der Name die folgenden Bedingungen erfüllt:
|
||||
* Buchstaben von a-z; A-Z
|
||||
* Umlaute äöüÄÖÜß
|
||||
* Leerzeichen und Bindestrich
|
||||
* 2-50 Zeichen
|
||||
*
|
||||
* @param $name
|
||||
* @return bool
|
||||
*/
|
||||
function userNameValidator($name)
|
||||
{
|
||||
$name = trim($name);
|
||||
$namePattern = '/^[a-zA-ZäöüÄÖÜß\s-]{2,50}$/u';
|
||||
|
||||
if (preg_match($namePattern, $name)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return preg_match($namePattern, $name) === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob die E-Mail-Adresse gültig ist
|
||||
* und höchstens 100 Zeichen enthält.
|
||||
*
|
||||
* @param $email
|
||||
* @return bool
|
||||
*/
|
||||
function userEmailValidator($email)
|
||||
{
|
||||
$email = trim($email);
|
||||
|
||||
if (filter_var($email, FILTER_VALIDATE_EMAIL) && mb_strlen($email) <= 100) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return filter_var($email, FILTER_VALIDATE_EMAIL) !== false
|
||||
&& mb_strlen($email) <= 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob das Passwort die folgenden Bedingungen erfüllt:
|
||||
* 8-72 Zeichen
|
||||
*
|
||||
* @param $password
|
||||
* @return bool
|
||||
*/
|
||||
function userPasswordValidator($password)
|
||||
{
|
||||
$zeichenAnzahl = mb_strlen($password);
|
||||
|
||||
if ($zeichenAnzahl >= 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 === '') {
|
||||
@@ -74,5 +31,3 @@ function userOptionalPasswordValidator($password)
|
||||
|
||||
return userPasswordValidator($password);
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user