Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b5fc79a2e7 | |||
| 24a3176f43 |
Generated
-18
@@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="dataSourceStorageLocal" created-in="IU-261.24374.151">
|
||||
<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>"</identifier-quote-string>
|
||||
</database-info>
|
||||
<case-sensitivity plain-identifiers="mixed" quoted-identifiers="mixed" />
|
||||
<secret-storage>master_key</secret-storage>
|
||||
<auth-provider>no-auth</auth-provider>
|
||||
<schema-mapping>
|
||||
<introspection-scope>
|
||||
<node kind="schema" qname="@" />
|
||||
</introspection-scope>
|
||||
</schema-mapping>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
||||
Generated
-12
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="articles" uuid="315cb5c9-2b0f-435b-b602-59823b160908">
|
||||
<driver-ref>sqlite.xerial</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
|
||||
<jdbc-url>jdbc:sqlite:$PROJECT_DIR$/db/articles</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
||||
@@ -53,8 +53,9 @@ if (!isset($_SESSION["user"])) {
|
||||
<input type="text" id="title" name="title"
|
||||
value="<?php echo htmlspecialchars($_SESSION['old_title'] ?? ''); unset($_SESSION['old_title']); ?>"
|
||||
placeholder="Titel hier eingeben" required>
|
||||
<textarea id="content" name="content" placeholder="Schreibe deinen Beitrag..."><?php if (isset($_SESSION['old_content']) && !empty($_SESSION['old_content'])){echo htmlspecialchars($_SESSION['old_content']); unset($_SESSION['old_content']);}elseif (isset($content) && !empty($content)){echo htmlspecialchars($content);}?></textarea>
|
||||
|
||||
<textarea id="content" name="content" placeholder="Schreibe deinen Beitrag...">
|
||||
<?php echo htmlspecialchars($_SESSION['old_content'] ?? ''); unset($_SESSION['old_content']); ?>
|
||||
</textarea>
|
||||
</main>
|
||||
|
||||
<!-- Seitenleiste -->
|
||||
|
||||
@@ -93,9 +93,6 @@ $isEditMode = (isset($_GET["edit"]) && $_GET["edit"] === "1") || !empty($error);
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<?php include_once "includes/alertMessages.php"?>
|
||||
|
||||
<h2 class="section-title">Meine Beiträge</h2>
|
||||
|
||||
<div class="articles-list">
|
||||
@@ -154,17 +151,6 @@ $isEditMode = (isset($_GET["edit"]) && $_GET["edit"] === "1") || !empty($error);
|
||||
class="edit-link-button">
|
||||
Bearbeiten
|
||||
</a>
|
||||
|
||||
<form action="php/controller/deleteArticle-controller.php" method="POST">
|
||||
<input type="hidden" name="id" value="<?php echo htmlspecialchars($userArticle->getID()); ?>">
|
||||
|
||||
<button type="submit"
|
||||
class="button"
|
||||
onclick="return confirm('Möchtest du diesen Artikel wirklich löschen?');">
|
||||
Löschen
|
||||
</button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
|
||||
+13
-13
@@ -58,27 +58,28 @@ include_once 'php/controller/showArticle-controller.php';
|
||||
Sie sind nicht berechtigt, diesen Beitrag zu bearbeiten.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "not_found_article"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Der zu bearbeitende Artikel wurde nicht gefunden. Bitte versuche es erneut.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
unset($_SESSION["message"]);
|
||||
?>
|
||||
<input type="text" id="title" name="title"
|
||||
value="<?php
|
||||
if (isset($_SESSION['old_title']) && !empty($_SESSION['old_title'])){
|
||||
if (isset($title) && !empty($title)){echo htmlspecialchars($title);
|
||||
}elseif (isset($_SESSION['old_title']) && !empty($_SESSION['old_title'])){
|
||||
echo htmlspecialchars($_SESSION['old_title']);
|
||||
unset($_SESSION['old_title']);
|
||||
}elseif (isset($title) && !empty($title)){
|
||||
echo htmlspecialchars($title);
|
||||
}
|
||||
|
||||
?>"
|
||||
placeholder="Titel hier eingeben" required>
|
||||
<textarea id="content" name="content" placeholder="Schreibe deinen Beitrag..."><?php if (isset($_SESSION['old_content']) && !empty($_SESSION['old_content'])){echo htmlspecialchars($_SESSION['old_content']); unset($_SESSION['old_content']);}elseif (isset($content) && !empty($content)){echo htmlspecialchars($content);}?></textarea>
|
||||
|
||||
<textarea id="content" name="content" placeholder="Schreibe deinen Beitrag...">
|
||||
<?php
|
||||
if (isset($content) && !empty($content)){echo htmlspecialchars($content);
|
||||
}elseif (isset($_SESSION['old_content']) && !empty($_SESSION['old_content'])){
|
||||
echo htmlspecialchars($_SESSION['old_content']);
|
||||
unset($_SESSION['old_content']);
|
||||
}
|
||||
?>
|
||||
</textarea>
|
||||
</main>
|
||||
|
||||
<!-- Seitenleiste -->
|
||||
@@ -137,11 +138,10 @@ include_once 'php/controller/showArticle-controller.php';
|
||||
<label for="tags">Schlagwörter</label>
|
||||
<input type="text" id="tags" name="tags"
|
||||
value="<?php
|
||||
if (isset($_SESSION['old_tags']) && !empty($_SESSION['old_tags'])){
|
||||
if (isset($tags) && !empty($tags)){echo htmlspecialchars($tags);
|
||||
} elseif (isset($_SESSION['old_tags']) && !empty($_SESSION['old_tags'])){
|
||||
echo htmlspecialchars($_SESSION['old_tags']);
|
||||
unset($_SESSION['old_tags']);
|
||||
} elseif (isset($tags) && !empty($tags)){
|
||||
echo htmlspecialchars($tags);
|
||||
}
|
||||
?>"
|
||||
placeholder="z.B. Technik, IT (mit Komma trennen)">
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "internal_error"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Es ist ein interner Fehler beim Speichern aufgetreten. Bitte versuche es erneut.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "missing_parameters"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Jeder Beitrag muss einen Titel, Kategorie und Inhalt besitzen.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_title"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Der Titel enthält ungültige Zeichen oder erfüllt die Länge von 5-120 Zeichen nicht.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_content"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Der Text erlaubt eine Länge von 10 bis maximal 7.000 Zeichen (ca. 1.000 Wörter).
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_category"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Die ausgewählte Kategorie ist ungültig.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_tags"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Ungültige Schlagworte gefunden. Erlaubt sind nur Buchstaben, Zahlen, Leerzeichen und Bindestriche (2-50 Zeichen).
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "validation_missing"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Bei der Validierung deiner Daten ist ein Fehler aufgetreten. Bitte versuche es erneut.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_category"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Diese Kategorie ist nicht gültig.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "missing_id"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Die Artikel-ID fehlt oder ist ungültig.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "not_found_article"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Der angeforderte Beitrag konnte nicht gefunden werden.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "unauthorized_access"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Du hast keine Berechtigung, diesen Beitrag zu bearbeiten oder zu löschen.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "article_deleted"): ?>
|
||||
<p class="alert-message is-success">
|
||||
Der Beitrag wurde erfolgreich gelöscht.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
unset($_SESSION["message"]);
|
||||
?>
|
||||
@@ -17,12 +17,12 @@ if ($pfad === "register") {
|
||||
}
|
||||
|
||||
if ($pfad === "logout") {
|
||||
include_once "php/controller/logout-controller.php";
|
||||
include_once "content/logout-controller.php";
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($pfad === "deleteAccount") {
|
||||
include_once "php/controller/deleteAccount-controller.php";
|
||||
include_once "content/deleteAccount-controller.php";
|
||||
exit();
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
require_once __DIR__ . "/../model/ArticleManager.php";
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
|
||||
if (isset($_SESSION["user_email"])) {
|
||||
$user = $_SESSION["user_email"];
|
||||
} else {
|
||||
$_SESSION = [];
|
||||
session_destroy();
|
||||
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (isset($_POST["id"]) && !empty($_POST["id"])) {
|
||||
$id = $_POST["id"];
|
||||
} else {
|
||||
$_SESSION["message"] = "missing_id";
|
||||
header("location: ../../index.php?pfad=profile");
|
||||
exit();
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$articleManager = ArticleManager::getInstance();
|
||||
$articleManager->deleteArticle($id, $user);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$_SESSION["message"] = $e->getMessage();
|
||||
header("location: ../../index.php?pfad=profile");
|
||||
exit();
|
||||
}
|
||||
|
||||
$_SESSION["message"] = "article_deleted";
|
||||
header("location: ../../index.php?pfad=profile");
|
||||
exit();
|
||||
}
|
||||
@@ -21,7 +21,7 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
|
||||
if (!isset($_POST["title"]) ||!isset($_POST["content"]) || !isset($_POST["category"])){
|
||||
$_SESSION["message"] = "missing_parameters";
|
||||
header("location: ../../index.php?pfad=updateArticle&id=$id");
|
||||
header("location: ../../index.php?pfad=updateArticle");
|
||||
exit();
|
||||
}else{
|
||||
$title = $_POST["title"];
|
||||
@@ -33,31 +33,31 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
// -------------------------------- Validierung der Daten: -------------------------
|
||||
if (!articleAuthorValidator($author)) {
|
||||
$_SESSION["message"] = "author_not_valid";
|
||||
header("location: ../../index.php?pfad=updateArticle&id=$id");
|
||||
header("location: ../../index.php?pfad=updateArticle");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!articleTitleValidator($title)) {
|
||||
$_SESSION["message"] = "invalid_title";
|
||||
header("location: ../../index.php?pfad=updateArticle&id=$id");
|
||||
header("location: ../../index.php?pfad=updateArticle");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!articleContentValidator($content)) {
|
||||
$_SESSION["message"] = "invalid_content";
|
||||
header("location: ../../index.php?pfad=updateArticle&id=$id");
|
||||
header("location: ../../index.php?pfad=updateArticle");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!articleCategoryValidator($category)) {
|
||||
$_SESSION["message"] = "invalid_category";
|
||||
header("location: ../../index.php?pfad=updateArticle&id=$id");
|
||||
header("location: ../../index.php?pfad=updateArticle");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!articleTagValidator($tags)) {
|
||||
$_SESSION["message"] = "invalid_tags";
|
||||
header("location: ../../index.php?pfad=updateArticle&id=$id");
|
||||
header("location: ../../index.php?pfad=updateArticle");
|
||||
exit();
|
||||
} else {
|
||||
$cleanedTags = [];
|
||||
@@ -83,7 +83,7 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
$articleManager->updateArticle($id ,$article, $author);
|
||||
} catch (Exception $e){
|
||||
$_SESSION["message"] = $e->getMessage();
|
||||
header("location: ../../index.php?pfad=updateArticle&id=$id");
|
||||
header("location: ../../index.php?pfad=updateArticle");
|
||||
exit();
|
||||
}
|
||||
$_SESSION["message"] = "article_updated";
|
||||
|
||||
@@ -19,7 +19,7 @@ class ArticleManager
|
||||
$articleManager->addArticle(
|
||||
"Satz des Pythagoras",
|
||||
"Der Satz des Pythagoras wurde von dem griechischen Philosophen Pythagoras von Samos formuliert und im dritten Jahrhundert vor Christus veröffentlicht. In der beigefügten Abbildung sehen wir ein rechtwinkliges Dreieck...",
|
||||
"mustermann@web.de",
|
||||
"max.mustermann",
|
||||
"mathe",
|
||||
"Dreiecke, Dreiecksseiten berechnen"
|
||||
);
|
||||
@@ -28,7 +28,7 @@ class ArticleManager
|
||||
$articleManager->addArticle(
|
||||
"Tunneleffekt",
|
||||
"Der Tunneleffekt ist ein quantenmechanisches Phänomen, bei dem Teilchen...",
|
||||
"mustermann@web.de",
|
||||
"max.mustermann",
|
||||
"physik",
|
||||
"Quantenphysik, Energie"
|
||||
);
|
||||
@@ -37,7 +37,7 @@ class ArticleManager
|
||||
$articleManager->addArticle(
|
||||
"Datenschutz vs Datensicherheit",
|
||||
"Datenschutz ist in unserer digital vernetzten Welt allgegenwärtig...",
|
||||
"mustermann@web.de",
|
||||
"max.mustermann",
|
||||
"informatik",
|
||||
"Daten, DSGVO"
|
||||
);
|
||||
|
||||
@@ -20,8 +20,10 @@ class DatabaseArticleManager implements ArticleManagerDAO {
|
||||
{
|
||||
if (!file_exists(__DIR__ . '/../../db/articles.db')) {
|
||||
try {
|
||||
|
||||
$db = $this->getConnection();
|
||||
$user = 'root';
|
||||
$pw = null;
|
||||
$dsn = 'sqlite:' . __DIR__ . '/../../db/articles.db';
|
||||
$db = new PDO($dsn, $user, $pw);
|
||||
|
||||
$db->exec("
|
||||
CREATE TABLE articles (
|
||||
@@ -147,7 +149,7 @@ class DatabaseArticleManager implements ArticleManagerDAO {
|
||||
|
||||
public function deleteArticle($id, $author)
|
||||
{
|
||||
$article = $this->getArticle($id);
|
||||
$article = getArticle($id);
|
||||
if (empty($article)) {
|
||||
throw new NotFoundException("not_found_article");
|
||||
}
|
||||
|
||||
@@ -36,19 +36,14 @@ class LocalArticleManager implements ArticleManagerDAO {
|
||||
* Speichert alle Artikel/Beiträge in der Datei.
|
||||
* @param $articles
|
||||
* @return void
|
||||
* @throws InternalServerErrorException
|
||||
* TODO: Exceptions implementieren.
|
||||
*/
|
||||
private function saveArticle($articles)
|
||||
public function saveArticle($articles)
|
||||
{
|
||||
try{
|
||||
file_put_contents(
|
||||
$this->file,
|
||||
json_encode($articles, JSON_PRETTY_PRINT)
|
||||
);
|
||||
}catch (Exception $e){
|
||||
throw new InternalServerErrorException($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function addArticle($title, $content, $author, $category, $tags)
|
||||
@@ -71,7 +66,7 @@ class LocalArticleManager implements ArticleManagerDAO {
|
||||
public function updateArticle($id, $article, $author)
|
||||
{
|
||||
if (empty($article)) {
|
||||
throw new NotFoundException("not_found_article");
|
||||
throw new InternalServerErrorException("internal_error");
|
||||
}
|
||||
|
||||
// Berechtigungsprüfung:
|
||||
|
||||
@@ -162,8 +162,6 @@ class LocalUserManager implements UserManagerDAO {
|
||||
/**
|
||||
* Löscht einen Benutzer anhand seiner E-Mail-Adresse.
|
||||
*
|
||||
* TODO: wenn ein Benutzer gelöscht wird, sollten dann auch seine Beiträge gelöscht werden?
|
||||
*
|
||||
* @param string $email E-Mail-Adresse des zu löschenden Benutzers
|
||||
* @return bool true, wenn der Benutzer gelöscht wurde, sonst false
|
||||
* @throws RuntimeException wenn die Benutzerdaten nicht gelesen oder gespeichert werden können
|
||||
|
||||
Reference in New Issue
Block a user