Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6c1a893f80 | |||
| 788e803e84 | |||
| 4d0f1de01c | |||
| e71ee8300e | |||
| f39885da10 | |||
| b7ca5bcfe2 | |||
| 57b0782577 | |||
| 4f524db221 | |||
| d5a3f4298f | |||
| b4a5c9c020 | |||
| 6d6f1f31b0 | |||
| cafffba921 | |||
| 8fa758d825 |
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="dataSourceStorageLocal" created-in="IU-261.25134.95">
|
<component name="dataSourceStorageLocal" created-in="IU-253.32098.101">
|
||||||
<data-source name="articles" uuid="315cb5c9-2b0f-435b-b602-59823b160908">
|
<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">
|
<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>"</identifier-quote-string>
|
<identifier-quote-string>"</identifier-quote-string>
|
||||||
|
|||||||
@@ -16,18 +16,21 @@
|
|||||||
|
|
||||||
## Bekannte Fehler und Mängel
|
## Bekannte Fehler und Mängel
|
||||||
- Bitte auf die gesetzten TODO's achten. Wenn Inhalte fehlen, sind sie i.d.R. als TODO kommentiert.
|
- Bitte auf die gesetzten TODO's achten. Wenn Inhalte fehlen, sind sie i.d.R. als TODO kommentiert.
|
||||||
- Die Suchseite und Kategorieseite packen momentan alle passenden Beiträge untereinander. Später sollen zunächst 10
|
- Die Kategorieseite listet momentan alle passenden Beiträge untereinander. Später sollen mit einem Paginator die neusten
|
||||||
Ergebnisse auf einer Seite angezeigt werden.
|
Beiträge nacheinander aufgelistet werden (ähnlich wie bei der Suche, wenn nach Fach gefiltert wird).
|
||||||
- Wenn ein Bild aus einem Beitrag entfernt wird, dann wird noch nicht die Datei im Pfad /uploads gelöscht.
|
- Wenn ein Bild aus einem Beitrag entfernt wird, dann wird noch nicht die Datei im Pfad /uploads gelöscht.
|
||||||
- id in showArticle-controller.php und updateArticle-controller.php wird nicht als gültige numerische ID geprüft.
|
- id in showArticle-controller.php und updateArticle-controller.php wird nicht als gültige numerische ID geprüft.
|
||||||
- sort in search-results-controller.php wird nicht gegen erlaubte Werte validiert.
|
- Bilder im Beitragseditor sollen zukünftig eine Bildunterschrift bekommen und größenverstellbar sein.
|
||||||
|
- Die Elemente eines Contents im Beitrag werden momentan stumpf untereinander aufgelistet. Soll später
|
||||||
|
sich responisve auch nebeneinander orientieren usw.
|
||||||
|
|
||||||
## Besonderheiten des Projektes
|
## Besonderheiten des Projektes
|
||||||
- Es wurde ein einfacher Beitrags-Editor erstellt. Mit diesem können Beiträge erstellt oder bearbeitet werden.
|
- Es wurde AJAX verwendet, um asynchrone Erstellung von Kommentaren zu implementieren. Es ermöglicht dem Nutzer, einen
|
||||||
Es handelt es sich um eine einfache Version. Später sollen z.B. Bilder und die Positionierung der Elemente folgen.
|
Kommentar abzusenden, ohne dass die gesamte Webseite neu geladen werden muss.
|
||||||
- Es sind drei Dummy-Beiträge für den Nutzer max.mustermann hinterlegt.
|
- Mit JavaScript werden auch clientseitig die Kommentare visuell hinzugefügt und die Kommentarbäume aufgebaut.
|
||||||
- Die Such-Seite umfasst eine Such- und Sortierfunktion. Jedoch fehlt noch eine
|
- JavaScript wird verwendet, um im erweitertem Beitragseditor clientseitig einzelne Content-Boxen erstellen und löschen
|
||||||
Filterfunktion (z.B. nur Mathe anzeigen).
|
zu können.
|
||||||
|
- JavaScript wird ebenfalls verwendet, um in die Suchergebnisse clientseitig zu sortieren.
|
||||||
|
|
||||||
## Sonstiges
|
## Sonstiges
|
||||||
- Das Datenschema befindet sich unter /planung/Datenschema.pdf
|
- Das Datenschema befindet sich unter /planung/Datenschema.pdf
|
||||||
@@ -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>
|
||||||
@@ -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
@@ -11,8 +11,8 @@ $error = $error ?? null;
|
|||||||
|
|
||||||
<h1>Bitte anmelden</h1>
|
<h1>Bitte anmelden</h1>
|
||||||
|
|
||||||
<?php if ($error): ?>
|
<?php if (!empty($error)): ?>
|
||||||
<p style="color:red;">
|
<p class="alert-message is-error">
|
||||||
<?php echo htmlspecialchars($error); ?>
|
<?php echo htmlspecialchars($error); ?>
|
||||||
</p>
|
</p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
@@ -41,6 +41,12 @@ $error = $error ?? null;
|
|||||||
anmelden
|
anmelden
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<div class="register-link">
|
||||||
|
<a href="index.php?pfad=password-forgotten">
|
||||||
|
Passwort vergessen?
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="register-link">
|
<div class="register-link">
|
||||||
<a href="index.php?pfad=register">
|
<a href="index.php?pfad=register">
|
||||||
Noch keinen Account? Jetzt hier registrieren!
|
Noch keinen Account? Jetzt hier registrieren!
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
$error = $error ?? null;
|
$error = $error ?? null;
|
||||||
|
$success = $success ?? null;
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
@@ -12,11 +13,17 @@ $error = $error ?? null;
|
|||||||
<h1>Jetzt Registrieren!</h1>
|
<h1>Jetzt Registrieren!</h1>
|
||||||
|
|
||||||
<?php if (!empty($error)): ?>
|
<?php if (!empty($error)): ?>
|
||||||
<p class="alert-message is-error" style="color:red;">
|
<p class="alert-message is-error">
|
||||||
<?php echo htmlspecialchars($error); ?>
|
<?php echo htmlspecialchars($error); ?>
|
||||||
</p>
|
</p>
|
||||||
<?php endif; ?>
|
<?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">
|
<form method="post" action="index.php?pfad=register">
|
||||||
|
|
||||||
<p class="input-label">Email:</p>
|
<p class="input-label">Email:</p>
|
||||||
|
|||||||
@@ -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
@@ -130,13 +130,6 @@ h1 {
|
|||||||
color: #1f2937;
|
color: #1f2937;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input-label {
|
|
||||||
margin-bottom: 5px;
|
|
||||||
font-weight: bold;
|
|
||||||
width: 100%;
|
|
||||||
color: #1f2937;
|
|
||||||
}
|
|
||||||
|
|
||||||
.login-input {
|
.login-input {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
@@ -210,14 +203,6 @@ h1 {
|
|||||||
.form-container {
|
.form-container {
|
||||||
width: 90%;
|
width: 90%;
|
||||||
max-width: 600px;
|
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;
|
flex: 1 1 450px;
|
||||||
padding: 30px;
|
padding: 30px;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
@@ -225,4 +210,19 @@ h1 {
|
|||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
box-shadow: 0 6px 20px rgba(0,0,0,0.1);
|
box-shadow: 0 6px 20px rgba(0,0,0,0.1);
|
||||||
box-sizing: border-box;
|
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;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<?php
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<?php
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<?php
|
||||||
@@ -17,6 +17,9 @@ if ($pfad === "login") {
|
|||||||
if ($pfad === "register") {
|
if ($pfad === "register") {
|
||||||
include_once "php/controller/register-controller.php";
|
include_once "php/controller/register-controller.php";
|
||||||
}
|
}
|
||||||
|
if ($pfad === "password-forgotten") {
|
||||||
|
include_once "php/controller/password-forgotten-controller.php";
|
||||||
|
}
|
||||||
|
|
||||||
if ($pfad === "logout") {
|
if ($pfad === "logout") {
|
||||||
include_once "php/controller/logout-controller.php";
|
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.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ require_once "php/model/UserManager.php";
|
|||||||
require_once "php/validator/user-validator.php";
|
require_once "php/validator/user-validator.php";
|
||||||
|
|
||||||
$error = null;
|
$error = null;
|
||||||
|
$success = null;
|
||||||
|
|
||||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||||
|
|
||||||
@@ -24,20 +25,71 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|||||||
try {
|
try {
|
||||||
$dao = UserManager::getInstance();
|
$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;
|
if (!is_dir("data/pending") && !mkdir("data/pending", 0777, true)) {
|
||||||
$_SESSION["user_email"] = $email;
|
throw new RuntimeException("Ordner data/pending konnte nicht erstellt werden.");
|
||||||
|
}
|
||||||
|
|
||||||
header("Location: index.php");
|
if (!is_writable("data/mails")) {
|
||||||
exit();
|
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) {
|
} catch (Exception $e) {
|
||||||
$error = "Die Registrierung konnte nicht gespeichert werden.";
|
$error = "Die Registrierung konnte nicht verarbeitet werden.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ require_once '../model/ArticleManager.php';
|
|||||||
require_once '../model/Article.php';
|
require_once '../model/Article.php';
|
||||||
require_once '../validator/article-validator.php';
|
require_once '../validator/article-validator.php';
|
||||||
|
|
||||||
if (!isset($_SESSION["user"])) {
|
if (!isset($_SESSION["user_email"])) {
|
||||||
header("Location: index.php?pfad=login");
|
header("Location: index.php?pfad=login");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,7 @@ if (!isset($_SESSION["user"])) {
|
|||||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||||
$_SESSION["old_title"] = $_POST["title"] ?? '';
|
$_SESSION["old_title"] = $_POST["title"] ?? '';
|
||||||
$_SESSION["old_content"] = $_POST["content"] ?? '';
|
$_SESSION["old_content"] = $_POST["content"] ?? '';
|
||||||
$_SESSION["old_category"] = $_POST["category"] ?? ''; // TODO: die Kategorie im Dropdown setzen, wenn der Editor erneut geöffnet wird.
|
$_SESSION["old_category"] = $_POST["category"] ?? '';
|
||||||
$_SESSION["old_tags"] = $_POST["tags"] ?? '';
|
$_SESSION["old_tags"] = $_POST["tags"] ?? '';
|
||||||
|
|
||||||
if (isset($_GET["id"]) && !empty($_GET["id"])) {
|
if (isset($_GET["id"]) && !empty($_GET["id"])) {
|
||||||
@@ -30,7 +30,7 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|||||||
try {
|
try {
|
||||||
$articleManager = ArticleManager::getInstance();
|
$articleManager = ArticleManager::getInstance();
|
||||||
$article = $articleManager->getArticle($id);
|
$article = $articleManager->getArticle($id);
|
||||||
if ($article->getAuthor() != $_SESSION["user"]->getUsername()) {
|
if ($article->getAuthor() != $_SESSION["user_email"]) {
|
||||||
$_SESSION["message"] = "unauthorized_access";
|
$_SESSION["message"] = "unauthorized_access";
|
||||||
header("location: ../../index.php");
|
header("location: ../../index.php");
|
||||||
exit();
|
exit();
|
||||||
|
|||||||
Reference in New Issue
Block a user