Compare commits

...

8 Commits

Author SHA1 Message Date
caroline.slt 6c1a893f80 Passwort vergessen Funktion 2026-06-26 00:05:45 +02:00
caroline.slt 788e803e84 Passwort vergessen Funktion 2026-06-25 23:45:17 +02:00
caroline.slt 4d0f1de01c Passwort vergessen Funktion 2026-06-25 23:40:33 +02:00
caroline.slt e71ee8300e Qualitätsanpassungen 2026-06-25 23:23:55 +02:00
caroline.slt f39885da10 CSS Anpassungen 2026-06-25 23:05:49 +02:00
caroline.slt b7ca5bcfe2 test rückgängig machen 2026-06-25 22:57:35 +02:00
caroline.slt 57b0782577 test 2026-06-25 22:53:45 +02:00
caroline.slt 4f524db221 Implementierung 2026-06-25 22:46:14 +02:00
14 changed files with 386 additions and 28 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="dataSourceStorageLocal" created-in="IU-261.24374.151">
<component name="dataSourceStorageLocal" created-in="IU-253.32098.101">
<data-source name="articles" uuid="315cb5c9-2b0f-435b-b602-59823b160908">
<database-info product="SQLite" version="3.51.1" jdbc-version="4.2" driver-name="SQLite JDBC" driver-version="3.51.1.0" dbms="SQLITE" exact-version="3.51.1" exact-driver-version="3.51">
<identifier-quote-string>&quot;</identifier-quote-string>
+65
View File
@@ -0,0 +1,65 @@
<?php
require_once "php/model/UserManager.php";
$token = basename($_GET["token"] ?? "");
$file = "data/pending-password/" . $token . ".json";
$title = "Passwort zurücksetzen";
$message = "";
$link = "";
$isSuccess = false;
if (!file_exists($file)) {
$message = "Der Bestätigungslink ist ungültig oder bereits abgelaufen.";
} else {
$data = json_decode(file_get_contents($file), true);
if ($data === null || empty($data["email"]) || empty($data["password"])) {
$message = "Die Daten zur Passwortänderung konnten nicht gelesen werden.";
} else {
try {
$dao = UserManager::getInstance();
$user = $dao->findUser($data["email"]);
if ($user !== null) {
$dao->updateUser(
$user["email"],
$user["email"],
$user["vorname"],
$user["nachname"],
$data["password"]
);
unlink($file);
$title = "Passwort geändert";
$message = "Ihr Passwort wurde erfolgreich geändert. Sie können sich jetzt anmelden.";
$link = '<a class="button confirm-button" href="index.php?pfad=login">Zum Login</a>';
$isSuccess = true;
} else {
unlink($file);
$message = "Der Benutzer konnte nicht gefunden werden.";
}
} catch (Exception $e) {
$message = "Das Passwort konnte nicht geändert werden.";
}
}
}
?>
<main class="login-page">
<div class="login-container">
<h1><?php echo htmlspecialchars($title); ?></h1>
<p class="alert-message <?php echo $isSuccess ? 'is-success' : 'is-error'; ?> confirm-message">
<?php echo htmlspecialchars($message); ?>
</p>
<?php echo $link; ?>
</div>
</main>
+68
View File
@@ -0,0 +1,68 @@
<?php
require_once "php/model/UserManager.php";
$token = basename($_GET["token"] ?? "");
$file = "data/pending/" . $token . ".json";
$title = "Registrierung";
$message = "";
$link = "";
$isSuccess = false;
if (!file_exists($file)) {
$message = "Der Registrierungslink ist ungültig oder bereits abgelaufen.";
} else {
$data = json_decode(file_get_contents($file), true);
if ($data === null) {
$message = "Die Registrierungsdaten konnten nicht gelesen werden.";
} elseif (
empty($data["email"]) ||
empty($data["vorname"]) ||
empty($data["nachname"]) ||
empty($data["password"])
) {
$message = "Die Registrierungsdaten sind unvollständig.";
} else {
try {
$dao = UserManager::getInstance();
if ($dao->findUser($data["email"]) === null) {
$dao->addUser(
$data["email"],
$data["vorname"],
$data["nachname"],
$data["password"]
);
}
unlink($file);
$title = "Registrierung erfolgreich";
$message = "Ihre Registrierung wurde erfolgreich abgeschlossen. Sie können sich jetzt anmelden.";
$link = '<a class="button confirm-button" href="index.php?pfad=login">Zum Login</a>';
$isSuccess = true;
} catch (Exception $e) {
$message = "Die Registrierung konnte nicht abgeschlossen werden.";
}
}
}
?>
<main class="login-page">
<div class="login-container">
<h1><?php echo htmlspecialchars($title); ?></h1>
<p class="alert-message <?php echo $isSuccess ? 'is-success' : 'is-error'; ?> confirm-message">
<?php echo htmlspecialchars($message); ?>
</p>
<?php echo $link; ?>
</div>
</main>
+8 -2
View File
@@ -11,8 +11,8 @@ $error = $error ?? null;
<h1>Bitte anmelden</h1>
<?php if ($error): ?>
<p style="color:red;">
<?php if (!empty($error)): ?>
<p class="alert-message is-error">
<?php echo htmlspecialchars($error); ?>
</p>
<?php endif; ?>
@@ -41,6 +41,12 @@ $error = $error ?? null;
anmelden
</button>
<div class="register-link">
<a href="index.php?pfad=password-forgotten">
Passwort vergessen?
</a>
</div>
<div class="register-link">
<a href="index.php?pfad=register">
Noch keinen Account? Jetzt hier registrieren!
+54
View File
@@ -0,0 +1,54 @@
<?php
$error = $error ?? null;
$success = $success ?? null;
?>
<main class="login-page">
<div class="login-container">
<h1>Passwort vergessen</h1>
<?php if (!empty($error)): ?>
<p class="alert-message is-error">
<?php echo htmlspecialchars($error); ?>
</p>
<?php endif; ?>
<?php if (!empty($success)): ?>
<p class="alert-message is-success">
<?php echo $success; ?>
</p>
<?php endif; ?>
<form method="post" action="index.php?pfad=password-forgotten">
<p class="input-label">E-Mail-Adresse:</p>
<input type="email"
name="email"
class="login-input"
placeholder="E-Mail-Adresse"
required>
<p class="input-label">Neues Passwort:</p>
<input type="password"
name="password"
class="login-input"
placeholder="Neues Passwort"
required>
<button type="submit"
name="passwordForgottenSubmit"
class="button">
Passwort zurücksetzen
</button>
<div class="register-link">
<a href="index.php?pfad=login">
Zurück zum Login
</a>
</div>
</form>
</div>
</main>
+8 -1
View File
@@ -1,5 +1,6 @@
<?php
$error = $error ?? null;
$success = $success ?? null;
?>
<!--
@@ -12,11 +13,17 @@ $error = $error ?? null;
<h1>Jetzt Registrieren!</h1>
<?php if (!empty($error)): ?>
<p class="alert-message is-error" style="color:red;">
<p class="alert-message is-error">
<?php echo htmlspecialchars($error); ?>
</p>
<?php endif; ?>
<?php if (!empty($success)): ?>
<p class="alert-message is-success">
<?php echo $success; ?>
</p>
<?php endif; ?>
<form method="post" action="index.php?pfad=register">
<p class="input-label">Email:</p>
+24
View File
@@ -0,0 +1,24 @@
<?php
/*
* Zeigt den Inhalt einer simulierten E-Mail an.
* Die Datei wird über einen zufällig erzeugten Token geladen.
*/
$token = basename($_GET["token"] ?? "");
$file = __DIR__ . "/../data/mails/" . $token . ".html";
if (!file_exists($file)) {
echo "<p>Datei nicht gefunden.</p>";
exit();
}
?>
<main class="login-page">
<div class="login-container">
<h1>Simulierte E-Mail</h1>
<?php include $file; ?>
</div>
</main>
+15 -15
View File
@@ -130,13 +130,6 @@ h1 {
color: #1f2937;
}
.input-label {
margin-bottom: 5px;
font-weight: bold;
width: 100%;
color: #1f2937;
}
.login-input {
width: 100%;
padding: 12px;
@@ -210,14 +203,6 @@ h1 {
.form-container {
width: 90%;
max-width: 600px;
padding: 30px;
background-color: white;
border: 1px solid #dbe3ec;
border-radius: 10px;
box-shadow: 0 6px 20px rgba(0,0,0,0.1);
}
.form-container {
flex: 1 1 450px;
padding: 30px;
background-color: white;
@@ -225,4 +210,19 @@ h1 {
border-radius: 10px;
box-shadow: 0 6px 20px rgba(0,0,0,0.1);
box-sizing: border-box;
}
/* Darstellung der Registrierungsbestätigung */
.confirm-message {
text-align: center;
margin: 20px 0;
}
/* Anpassung des Login-Buttons auf der Bestätigungsseite */
.confirm-button {
display: block;
width: 100%;
text-align: center;
text-decoration: none;
box-sizing: border-box;
}
+1
View File
@@ -0,0 +1 @@
<?php
+1
View File
@@ -0,0 +1 @@
<?php
+1
View File
@@ -0,0 +1 @@
<?php
+3
View File
@@ -17,6 +17,9 @@ if ($pfad === "login") {
if ($pfad === "register") {
include_once "php/controller/register-controller.php";
}
if ($pfad === "password-forgotten") {
include_once "php/controller/password-forgotten-controller.php";
}
if ($pfad === "logout") {
include_once "php/controller/logout-controller.php";
@@ -0,0 +1,76 @@
<?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"] ?? "");
$plainPassword = $_POST["password"] ?? "";
if (!userEmailValidator($email)) {
$error = "Bitte gib eine gültige E-Mail-Adresse ein.";
} 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 (!is_dir("data/mails") && !mkdir("data/mails", 0777, true)) {
throw new RuntimeException("Ordner data/mails konnte nicht erstellt werden.");
}
if (!is_dir("data/pending-password") && !mkdir("data/pending-password", 0777, true)) {
throw new RuntimeException("Ordner data/pending-password konnte nicht erstellt werden.");
}
if (!is_writable("data/mails") || !is_writable("data/pending-password")) {
throw new RuntimeException("Ordner sind nicht beschreibbar.");
}
if ($existingUser !== null) {
$pendingData = [
"email" => $email,
"password" => $plainPassword
];
file_put_contents(
"data/pending-password/" . $token . ".json",
json_encode($pendingData, JSON_PRETTY_PRINT)
);
}
if ($existingUser !== null) {
$mailContent = "
<h2>Passwort zurücksetzen</h2>
<p>Falls Sie diese Anfrage nicht gestellt haben, können Sie diese Nachricht ignorieren.</p>
<p>
<a href='index.php?pfad=confirm-password&token=$token'>
Passwortänderung bestätigen
</a>
</p>
";
} else {
$mailContent = "
<h2>Passwort zurücksetzen</h2>
<p>Falls Sie diese Anfrage nicht gestellt haben, können Sie diese Nachricht ignorieren.</p>
<p>Für diese E-Mail-Adresse wurde kein Konto gefunden.</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 Passwortänderung konnte nicht verarbeitet werden.";
}
}
}
+61 -9
View File
@@ -4,6 +4,7 @@ require_once "php/model/UserManager.php";
require_once "php/validator/user-validator.php";
$error = null;
$success = null;
if ($_SERVER["REQUEST_METHOD"] === "POST") {
@@ -24,20 +25,71 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
try {
$dao = UserManager::getInstance();
$password = password_hash($plainPassword, PASSWORD_DEFAULT);
// Token für die simulierte E-Mail und die spätere Bestätigung erzeugen.
$token = bin2hex(random_bytes(16));
$existingUser = $dao->findUser($email);
$dao->addUser($email, $vorname, $nachname, $password);
if (!is_dir("data/mails") && !mkdir("data/mails", 0777, true)) {
throw new RuntimeException("Ordner data/mails konnte nicht erstellt werden.");
}
$_SESSION["user"] = $vorname . " " . $nachname;
$_SESSION["user_email"] = $email;
if (!is_dir("data/pending") && !mkdir("data/pending", 0777, true)) {
throw new RuntimeException("Ordner data/pending konnte nicht erstellt werden.");
}
header("Location: index.php");
exit();
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.");
}
if ($existingUser === null) {
$password = password_hash($plainPassword, PASSWORD_DEFAULT);
$pendingData = [
"email" => $email,
"vorname" => $vorname,
"nachname" => $nachname,
"password" => $password
];
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);
// Neutrale Meldung, damit nicht sichtbar wird, ob die E-Mail bereits registriert ist.
$success = 'Weitere Infos finden Sie in der Datei
<a href="index.php?pfad=show-mail&token=' . htmlspecialchars($token) . '" target="_blank">xy</a>.';
} catch (InvalidArgumentException $e) {
$error = $e->getMessage();
} catch (Exception $e) {
$error = "Die Registrierung konnte nicht gespeichert werden.";
$error = "Die Registrierung konnte nicht verarbeitet werden.";
}
}
}