93 lines
3.6 KiB
PHP
93 lines
3.6 KiB
PHP
<?php
|
|
|
|
require_once "php/model/UserManager.php";
|
|
require_once "php/validator/user-validator.php";
|
|
|
|
$error = null;
|
|
$success = null;
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|
|
|
$email = trim($_POST["email"] ?? "");
|
|
$vorname = trim($_POST["vorname"] ?? "");
|
|
$nachname = trim($_POST["nachname"] ?? "");
|
|
$plainPassword = $_POST["password"] ?? "";
|
|
|
|
if (!userEmailValidator($email)) {
|
|
$error = "Bitte gib eine gültige E-Mail-Adresse ein.";
|
|
} elseif (!userNameValidator($vorname)) {
|
|
$error = "Der Vorname muss 2 bis 20 Zeichen lang sein und darf nur Buchstaben, Umlaute, Leerzeichen und Bindestriche enthalten.";
|
|
} elseif (!userNameValidator($nachname)) {
|
|
$error = "Der Nachname muss 2 bis 20 Zeichen lang sein und darf nur Buchstaben, Umlaute, Leerzeichen und Bindestriche enthalten.";
|
|
} elseif (!userPasswordValidator($plainPassword)) {
|
|
$error = "Das Passwort muss 5 bis 12 Zeichen lang sein.";
|
|
} else {
|
|
try {
|
|
$dao = UserManager::getInstance();
|
|
|
|
$token = bin2hex(random_bytes(16));
|
|
$existingUser = $dao->findUser($email);
|
|
|
|
if ($existingUser === null) {
|
|
$password = password_hash($plainPassword, PASSWORD_DEFAULT);
|
|
|
|
$pendingData = [
|
|
"email" => $email,
|
|
"vorname" => $vorname,
|
|
"nachname" => $nachname,
|
|
"password" => $password
|
|
];
|
|
|
|
if (!is_dir("data/mails") && !mkdir("data/mails", 0777, true)) {
|
|
throw new RuntimeException("Ordner data/mails konnte nicht erstellt werden.");
|
|
}
|
|
|
|
if (!is_dir("data/pending") && !mkdir("data/pending", 0777, true)) {
|
|
throw new RuntimeException("Ordner data/pending konnte nicht erstellt werden.");
|
|
}
|
|
|
|
if (!is_writable("data/mails")) {
|
|
throw new RuntimeException("Ordner data/mails ist nicht beschreibbar.");
|
|
}
|
|
|
|
if (!is_writable("data/pending")) {
|
|
throw new RuntimeException("Ordner data/pending ist nicht beschreibbar.");
|
|
}
|
|
|
|
file_put_contents(
|
|
"data/pending/" . $token . ".json",
|
|
json_encode($pendingData, JSON_PRETTY_PRINT)
|
|
);
|
|
|
|
$mailContent = "
|
|
<h2>Registrierung bestätigen</h2>
|
|
<p>Bitte ignorieren Sie diese Nachricht, wenn Sie sich nicht registrieren wollten.</p>
|
|
<p>
|
|
<a href='index.php?pfad=confirm-register&token=$token'>
|
|
Registrierung bestätigen
|
|
</a>
|
|
</p>
|
|
";
|
|
} else {
|
|
$mailContent = "
|
|
<h2>Registrierung</h2>
|
|
<p>Bitte ignorieren Sie diese Nachricht, wenn Sie sich nicht registrieren wollten.</p>
|
|
<p>Sie sind bereits registriert.</p>
|
|
<p>
|
|
<a href='index.php?pfad=password-forgotten'>
|
|
Passwort vergessen
|
|
</a>
|
|
</p>
|
|
";
|
|
}
|
|
|
|
file_put_contents("data/mails/" . $token . ".html", $mailContent);
|
|
|
|
$success = 'Weitere Infos finden Sie in der Datei
|
|
<a href="index.php?pfad=show-mail&token=' . htmlspecialchars($token) . '" target="_blank">xy</a>.';
|
|
|
|
} catch (Exception $e) {
|
|
$error = "Die Registrierung konnte nicht verarbeitet werden.";
|
|
}
|
|
}
|
|
} |