Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c32f31204e | |||
| 722f4055a5 |
-42
@@ -1,42 +0,0 @@
|
|||||||
<DataSourcesHistory>
|
|
||||||
<DataSourceFromHistory isRemovedFromProject="true">
|
|
||||||
<data-source source="LOCAL" name="articles" uuid="a0abcd0a-1d6f-40e4-88be-f442bcb431ba">
|
|
||||||
<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" />
|
|
||||||
<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>
|
|
||||||
<secret-storage>master_key</secret-storage>
|
|
||||||
<auth-provider>no-auth</auth-provider>
|
|
||||||
<schema-mapping>
|
|
||||||
<introspection-scope>
|
|
||||||
<node kind="schema" qname="@" />
|
|
||||||
</introspection-scope>
|
|
||||||
</schema-mapping>
|
|
||||||
<working-dir>$ProjectFileDir$</working-dir>
|
|
||||||
</data-source>
|
|
||||||
</DataSourceFromHistory>
|
|
||||||
<DataSourceFromHistory isRemovedFromProject="false">
|
|
||||||
<data-source source="LOCAL" 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" />
|
|
||||||
<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>
|
|
||||||
<secret-storage>master_key</secret-storage>
|
|
||||||
<auth-provider>no-auth</auth-provider>
|
|
||||||
<schema-mapping>
|
|
||||||
<introspection-scope>
|
|
||||||
<node kind="schema" qname="@" />
|
|
||||||
</introspection-scope>
|
|
||||||
</schema-mapping>
|
|
||||||
<working-dir>$ProjectFileDir$</working-dir>
|
|
||||||
</data-source>
|
|
||||||
</DataSourceFromHistory>
|
|
||||||
</DataSourcesHistory>
|
|
||||||
@@ -19,17 +19,13 @@ Jeweils im Format `Anmeldename, Passwort, Mailadresse`:
|
|||||||
- 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 Navbar hat noch keine onHover-Effekte und erschwert etwas die Bedienung.
|
- Die Navbar hat noch keine onHover-Effekte und erschwert etwas die Bedienung.
|
||||||
- Suchleiste in der Nav ist in der mobilen Ansicht etwas schmal. Ggf. ein alternatives (kleineres) Logo implementieren.
|
- Suchleiste in der Nav ist in der mobilen Ansicht etwas schmal. Ggf. ein alternatives (kleineres) Logo implementieren.
|
||||||
- Die Suchseite und Kategorieseite packen momentan alle passenden Beiträge untereinander. Später sollen zunächst 10
|
|
||||||
Ergebnisse auf einer Seite angezeigt werden.
|
|
||||||
|
|
||||||
## 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 ein einfacher Beitrags-Editor erstellt. Mit diesem können Beiträge erstellt oder bearbeitet werden.
|
||||||
Es handelt es sich um eine einfache Version. Später sollen z.B. Bilder und die Positionierung der Elemente folgen.
|
Es handelt es sich um eine einfache Version. Später sollen z.B. Bilder und die Positionierung der Elemente folgen.
|
||||||
- Es sind drei Dummy-Beiträge für den Nutzer max.mustermann hinterlegt.
|
- Es sind drei Dummy-Beiträge für den Nutzer max.mustermann hinterlegt.
|
||||||
- Beim Verwenden der Navbar-Links bitte Folgendes beachten: nur die Kategorien Physik, Mathe, Informatik führen
|
- Beim Verwenden der Navbar-Links bitte Folgendes beachten: nur die Kategorien Physik, Mathe, Informatik führen exemplarisch auf eine Beispiel-Seite.
|
||||||
exemplarisch auf eine Beispiel-Seite.
|
|
||||||
Die anderen Links sind erstmal Platzhalter und führen auf eine 404-Seite.
|
Die anderen Links sind erstmal Platzhalter und führen auf eine 404-Seite.
|
||||||
- Die Such-Seite umfasst eine Suchfunktion (aber noch nicht nach Tags) und Sortierfunktion. Jedoch fehlt noch eine
|
- Die Such-Seite umfasst eine Suchfunktion (aber noch nicht nach Tags) und Sortierfunktion. Jedoch fehlt noch eine Filterfunktion (z.B. nur Mathe anzeigen).
|
||||||
Filterfunktion (z.B. nur Mathe anzeigen).
|
Wenn die Filterfunktion implementiert ist, dann können die statischen Seiten "Informatik", "Mathe", "Physik" entfernt und dynamisch auf der Suchseite
|
||||||
Wenn die Filterfunktion implementiert ist, dann können die statischen Seiten "Informatik", "Mathe", "Physik" entfernt
|
nach gefiltertem Fach angezeigt werden. (Vorläufige showCategory.php implementiert)
|
||||||
und dynamisch auf der Suchseite nach gefiltertem Fach angezeigt werden. (Vorläufige showCategory.php implementiert).
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
require_once "php/model/LocalUserDAO.php";
|
||||||
|
|
||||||
|
$dao = new LocalUserDAO();
|
||||||
|
|
||||||
|
/*
|
||||||
|
Deregistrierung
|
||||||
|
Funktion: Entfernt User aus Dummy-Daten und beendet Session
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (isset($_SESSION["user_email"])) {
|
||||||
|
$dao->deleteUser($_SESSION["user_email"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$_SESSION = [];
|
||||||
|
session_destroy();
|
||||||
|
|
||||||
|
header("Location: index.php");
|
||||||
|
exit();
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
<FilesMatch "\.db">
|
|
||||||
deny from all
|
|
||||||
</FilesMatch>
|
|
||||||
@@ -17,12 +17,12 @@ if ($pfad === "register") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($pfad === "logout") {
|
if ($pfad === "logout") {
|
||||||
include_once "content/logout-controller.php";
|
include_once "content/logout.php";
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($pfad === "deleteAccount") {
|
if ($pfad === "deleteAccount") {
|
||||||
include_once "content/deleteAccount-controller.php";
|
include_once "content/deleteAccount.php";
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ SESSION_START();
|
|||||||
require_once '../model/LocalArticleManager.php';
|
require_once '../model/LocalArticleManager.php';
|
||||||
require_once '../model/ArticleManager.php';
|
require_once '../model/ArticleManager.php';
|
||||||
require_once '../validator/article-validator.php';
|
require_once '../validator/article-validator.php';
|
||||||
|
require_once "../model/LocalUserDAO.php";
|
||||||
|
|
||||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||||
$_SESSION["old_title"] = $_POST["title"] ?? '';
|
$_SESSION["old_title"] = $_POST["title"] ?? '';
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
require_once "php/model/UserManager.php";
|
|
||||||
|
|
||||||
/*
|
|
||||||
Deregistrierung
|
|
||||||
Funktion: Entfernt User aus der Datenbank und beendet die Session
|
|
||||||
*/
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
$dao = UserManager::getInstance();
|
|
||||||
|
|
||||||
if (isset($_SESSION["user_email"])) {
|
|
||||||
$dao->deleteUser($_SESSION["user_email"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$_SESSION = [];
|
|
||||||
session_destroy();
|
|
||||||
|
|
||||||
header("Location: index.php");
|
|
||||||
exit();
|
|
||||||
|
|
||||||
} catch (Exception $e) {
|
|
||||||
|
|
||||||
$_SESSION["message"] = "internal_error";
|
|
||||||
|
|
||||||
header("Location: index.php?pfad=profile");
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once "php/model/UserManager.php";
|
require_once "php/model/LocalUserDAO.php";
|
||||||
|
|
||||||
|
$dao = new LocalUserDAO();
|
||||||
$error = null;
|
$error = null;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -10,28 +11,25 @@ $error = null;
|
|||||||
*/
|
*/
|
||||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||||
|
|
||||||
try {
|
$email = $_POST["email"] ?? "";
|
||||||
|
$password = $_POST["password"] ?? "";
|
||||||
|
|
||||||
$dao = UserManager::getInstance();
|
$user = $dao->findUser($email);
|
||||||
|
|
||||||
$email = $_POST["email"] ?? "";
|
if ($user && password_verify($password, $user["password"])) {
|
||||||
$password = $_POST["password"] ?? "";
|
|
||||||
|
|
||||||
$user = $dao->findUser($email);
|
|
||||||
|
|
||||||
if ($user && password_verify($password, $user["password"])) {
|
|
||||||
|
|
||||||
|
if (isset($user["vorname"]) && isset($user["nachname"])) {
|
||||||
$_SESSION["user"] = $user["vorname"] . " " . $user["nachname"];
|
$_SESSION["user"] = $user["vorname"] . " " . $user["nachname"];
|
||||||
$_SESSION["user_email"] = $user["email"];
|
|
||||||
|
|
||||||
header("Location: index.php");
|
|
||||||
exit();
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$error = "Login fehlgeschlagen. Bitte überprüfe deine Eingaben.";
|
$_SESSION["user"] = $user["username"] ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception $e) {
|
$_SESSION["user_email"] = $user["email"];
|
||||||
$error = "Es ist ein interner Fehler aufgetreten. Bitte versuche es erneut.";
|
|
||||||
|
header("Location: index.php");
|
||||||
|
exit();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$error = "Login fehlgeschlagen. Bitte überprüfe deine Eingaben.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once "php/model/UserManager.php";
|
require_once "php/model/LocalUserDAO.php";
|
||||||
require_once "php/model/Article.php";
|
require_once "php/model/Article.php";
|
||||||
require_once "php/model/ArticleManager.php";
|
require_once "php/model/ArticleManager.php";
|
||||||
require_once "php/validator/user-validator.php";
|
require_once "php/validator/user-validator.php";
|
||||||
@@ -13,7 +13,7 @@ if (!isset($_SESSION["user"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$dao = UserManager::getInstance();
|
$dao = new LocalUserDAO();
|
||||||
|
|
||||||
$user = $dao->findUser($_SESSION["user_email"] ?? "");
|
$user = $dao->findUser($_SESSION["user_email"] ?? "");
|
||||||
|
|
||||||
@@ -38,15 +38,15 @@ try {
|
|||||||
$_GET["edit"] = "1";
|
$_GET["edit"] = "1";
|
||||||
|
|
||||||
} elseif (!userNameValidator($vorname)) {
|
} elseif (!userNameValidator($vorname)) {
|
||||||
$error = "Der Vorname muss 2 bis 20 Zeichen lang sein und darf nur Buchstaben, Leerzeichen und Bindestriche enthalten.";
|
$error = "Der Vorname muss 2 bis 50 Zeichen lang sein und darf nur Buchstaben, Leerzeichen und Bindestriche enthalten.";
|
||||||
$_GET["edit"] = "1";
|
$_GET["edit"] = "1";
|
||||||
|
|
||||||
} elseif (!userNameValidator($nachname)) {
|
} elseif (!userNameValidator($nachname)) {
|
||||||
$error = "Der Nachname muss 2 bis 20 Zeichen lang sein und darf nur Buchstaben, Leerzeichen und Bindestriche enthalten.";
|
$error = "Der Nachname muss 2 bis 50 Zeichen lang sein und darf nur Buchstaben, Leerzeichen und Bindestriche enthalten.";
|
||||||
$_GET["edit"] = "1";
|
$_GET["edit"] = "1";
|
||||||
|
|
||||||
} elseif (!userOptionalPasswordValidator($password)) {
|
} elseif (!userOptionalPasswordValidator($password)) {
|
||||||
$error = "Das Passwort muss 5 bis 12 Zeichen lang sein.";
|
$error = "Das Passwort muss 8 bis 72 Zeichen lang sein.";
|
||||||
$_GET["edit"] = "1";
|
$_GET["edit"] = "1";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
|
|
||||||
require_once 'php/model/Article.php';
|
require_once 'php/model/Article.php';
|
||||||
require_once 'php/model/ArticleManager.php';
|
require_once 'php/model/ArticleManager.php';
|
||||||
require_once "php/model/UserManager.php";
|
require_once "../model/LocalUserDAO.php";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$dao = UserManager::getInstance();
|
$dao = new LocalUserDAO();
|
||||||
$user = $dao->findUser($_SESSION["user_email"] ?? "");
|
$user = $dao->findUser($_SESSION["user_email"] ?? "");
|
||||||
|
|
||||||
$author = $user["email"];
|
$author = $user["email"];
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once "php/model/UserManager.php";
|
require_once "php/model/LocalUserDAO.php";
|
||||||
require_once "php/validator/user-validator.php";
|
require_once "php/validator/user-validator.php";
|
||||||
|
|
||||||
$error = null;
|
$error = null;
|
||||||
@@ -15,14 +15,14 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|||||||
if (!userEmailValidator($email)) {
|
if (!userEmailValidator($email)) {
|
||||||
$error = "Bitte gib eine gültige E-Mail-Adresse ein.";
|
$error = "Bitte gib eine gültige E-Mail-Adresse ein.";
|
||||||
} elseif (!userNameValidator($vorname)) {
|
} elseif (!userNameValidator($vorname)) {
|
||||||
$error = "Der Vorname muss 2 bis 20 Zeichen lang sein und darf nur Buchstaben, Umlaute, Leerzeichen und Bindestriche enthalten.";
|
$error = "Der Vorname muss 2 bis 50 Zeichen lang sein und darf nur Buchstaben, Umlaute, Leerzeichen und Bindestriche enthalten.";
|
||||||
} elseif (!userNameValidator($nachname)) {
|
} elseif (!userNameValidator($nachname)) {
|
||||||
$error = "Der Nachname muss 2 bis 20 Zeichen lang sein und darf nur Buchstaben, Umlaute, Leerzeichen und Bindestriche enthalten.";
|
$error = "Der Nachname muss 2 bis 50 Zeichen lang sein und darf nur Buchstaben, Umlaute, Leerzeichen und Bindestriche enthalten.";
|
||||||
} elseif (!userPasswordValidator($plainPassword)) {
|
} elseif (!userPasswordValidator($plainPassword)) {
|
||||||
$error = "Das Passwort muss 5 bis 12 Zeichen lang sein.";
|
$error = "Das Passwort muss 8 bis 72 Zeichen lang sein.";
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
$dao = UserManager::getInstance();
|
$dao = new LocalUserDAO();
|
||||||
|
|
||||||
$password = password_hash($plainPassword, PASSWORD_DEFAULT);
|
$password = password_hash($plainPassword, PASSWORD_DEFAULT);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once 'LocalArticleManager.php';
|
require_once 'LocalArticleManager.php';
|
||||||
require_once 'DatabaseArticleManager.php';
|
|
||||||
require_once 'Article.php';
|
require_once 'Article.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8,11 +7,11 @@ require_once 'Article.php';
|
|||||||
*
|
*
|
||||||
* @author Niklas Ortmann
|
* @author Niklas Ortmann
|
||||||
*/
|
*/
|
||||||
class ArticleManager
|
class ArticleManager extends LocalArticleManager
|
||||||
{
|
{
|
||||||
public static function getInstance()
|
public static function getInstance()
|
||||||
{
|
{
|
||||||
$articleManager = DatabaseArticleManager::getInstance(); // Hier kann zwischen dem lokalen und datenbankbasiertem ArticleManager gewechselt werden.
|
$articleManager = LocalArticleManager::getInstance(); // TODO: später durch DataBaseArticleManager ersetzen.
|
||||||
|
|
||||||
// Erstellen von Dummy-Beiträgen:
|
// Erstellen von Dummy-Beiträgen:
|
||||||
if($articleManager->getArticle(1) == null ){
|
if($articleManager->getArticle(1) == null ){
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ interface ArticleManagerDAO
|
|||||||
* @param $category string Kategorie des Beitrages
|
* @param $category string Kategorie des Beitrages
|
||||||
* @param $tags string optionale Schlagworte für eine bessere Suche
|
* @param $tags string optionale Schlagworte für eine bessere Suche
|
||||||
*
|
*
|
||||||
* @throws InternalServerErrorException
|
* Mögliche Exceptions:
|
||||||
|
* TODO: Exceptions implementieren.
|
||||||
*/
|
*/
|
||||||
public function addArticle($title, $content, $author, $category, $tags);
|
public function addArticle($title, $content, $author, $category, $tags);
|
||||||
|
|
||||||
@@ -36,33 +37,34 @@ interface ArticleManagerDAO
|
|||||||
* @throws InternalServerErrorException
|
* @throws InternalServerErrorException
|
||||||
* @throws NotFoundException
|
* @throws NotFoundException
|
||||||
* @throws UnauthorizedAccessException
|
* @throws UnauthorizedAccessException
|
||||||
|
* /
|
||||||
*/
|
*/
|
||||||
public function updateArticle($id, $article, $author);
|
public function updateArticle($id, $article, $author);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Löscht einen Beitrag aus übergebener ID und dem Nutzer, der die Löschung ausführt.
|
* Löscht einen Beitrag aus übergebener ID.
|
||||||
* @param $id
|
* @param $id
|
||||||
* @param $author
|
|
||||||
* @return void
|
* @return void
|
||||||
* @throws InternalServerErrorException
|
*
|
||||||
* @throws NotFoundException
|
* TODO: Exceptions implementieren.
|
||||||
* @throws UnauthorizedAccessException
|
|
||||||
*/
|
*/
|
||||||
public function deleteArticle($id, $author);
|
public function deleteArticle($id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Beitrag aufrufen.
|
* Beitrag aufrufen.
|
||||||
* $id ID des Beitrags
|
* $id ID des Beitrags
|
||||||
*
|
*
|
||||||
* @return Article
|
* @return Article
|
||||||
* @throws InternalServerErrorException
|
* Mögliche Exceptions:
|
||||||
|
* TODO: Exceptions implementieren.
|
||||||
*/
|
*/
|
||||||
public function getArticle($id);
|
public function getArticle($id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alle Beiträge aufrufen.
|
* Alle Beiträge aufrufen.
|
||||||
*
|
*
|
||||||
* @throws InternalServerErrorException
|
* Mögliche Exceptions:
|
||||||
|
* TODO: Exceptions implementieren.
|
||||||
*/
|
*/
|
||||||
public function getAllArticles();
|
public function getAllArticles();
|
||||||
|
|
||||||
@@ -70,7 +72,7 @@ interface ArticleManagerDAO
|
|||||||
* Gibt alle Beiträge eines Nutzer mit einer gegebenen ID aus.
|
* Gibt alle Beiträge eines Nutzer mit einer gegebenen ID aus.
|
||||||
* @param $author
|
* @param $author
|
||||||
* @return Article[]
|
* @return Article[]
|
||||||
* @throws InternalServerErrorException
|
* TODO: Exceptions implementieren.
|
||||||
*/
|
*/
|
||||||
public function getArticlesByAuthor($author);
|
public function getArticlesByAuthor($author);
|
||||||
|
|
||||||
@@ -87,7 +89,6 @@ interface ArticleManagerDAO
|
|||||||
* Gibt alle Beiträge einer gegebenen Kategorie aus.
|
* Gibt alle Beiträge einer gegebenen Kategorie aus.
|
||||||
* @param $category
|
* @param $category
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws InternalServerErrorException
|
|
||||||
*/
|
*/
|
||||||
public function getArticlesByCategory($category);
|
public function getArticlesByCategory($category);
|
||||||
|
|
||||||
|
|||||||
@@ -1,315 +0,0 @@
|
|||||||
<?php
|
|
||||||
require_once 'ArticleManagerDAO.php';
|
|
||||||
require_once 'Article.php';
|
|
||||||
/**
|
|
||||||
* Klasse: Eine SQLLite3 Lösung des ArticleManagerDAO.
|
|
||||||
*
|
|
||||||
* @author Niklas Ortmann
|
|
||||||
*/
|
|
||||||
class DatabaseArticleManager implements ArticleManagerDAO {
|
|
||||||
|
|
||||||
private static $instance = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Konstruktor
|
|
||||||
*
|
|
||||||
* Erstellt die Datenbankverbindung und die Tabelle articles.
|
|
||||||
* @throws InternalServerErrorException
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
if (!file_exists(__DIR__ . '/../../db/articles.db')) {
|
|
||||||
try {
|
|
||||||
$user = 'root';
|
|
||||||
$pw = null;
|
|
||||||
$dsn = 'sqlite:' . __DIR__ . '/../../db/articles.db';
|
|
||||||
$db = new PDO($dsn, $user, $pw);
|
|
||||||
|
|
||||||
$db->exec("
|
|
||||||
CREATE TABLE articles (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
title TEXT,
|
|
||||||
content TEXT,
|
|
||||||
author TEXT,
|
|
||||||
category TEXT,
|
|
||||||
tags TEXT,
|
|
||||||
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);");
|
|
||||||
unset($db);
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
throw new InternalServerErrorException($e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Baut die Verbindung zur Datenbank auf.
|
|
||||||
* @throws InternalServerErrorException
|
|
||||||
*/
|
|
||||||
private function getConnection()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$user = 'root';
|
|
||||||
$pw = null;
|
|
||||||
$dsn = 'sqlite:' . __DIR__ . '/../../db/articles.db';
|
|
||||||
return new PDO($dsn, $user, $pw);
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
throw new InternalServerErrorException($e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gibt die DatabaseArticleManager-Instanz zurück.
|
|
||||||
* @return DatabaseArticleManager
|
|
||||||
*/
|
|
||||||
public static function getInstance()
|
|
||||||
{
|
|
||||||
if (self::$instance == null) {
|
|
||||||
self::$instance = new DatabaseArticleManager();
|
|
||||||
}
|
|
||||||
return self::$instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addArticle($title, $content, $author, $category, $tags)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$db = $this->getConnection();
|
|
||||||
|
|
||||||
$sql = "INSERT INTO articles (title, content, author, category, tags)
|
|
||||||
VALUES (:title, :content, :author, :category, :tags);";
|
|
||||||
|
|
||||||
$command = $db->prepare($sql);
|
|
||||||
if (!$command) {
|
|
||||||
throw new InternalServerErrorException("internal_error");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verknüpft die übergebenen Parameter exakt mit den SQL-Platzhaltern
|
|
||||||
$success = $command->execute([
|
|
||||||
":title" => $title,
|
|
||||||
":content" => $content,
|
|
||||||
":author" => $author,
|
|
||||||
":category" => $category,
|
|
||||||
":tags" => $tags
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!$success) {
|
|
||||||
throw new InternalServerErrorException("internal_error");
|
|
||||||
}
|
|
||||||
|
|
||||||
return intval($db->lastInsertId());
|
|
||||||
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
throw new InternalServerErrorException($e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updateArticle($id, $article, $author)
|
|
||||||
{
|
|
||||||
if (empty($article)) {
|
|
||||||
throw new InternalServerErrorException("internal_error");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Berechtigungsprüfung analog zur lokalen Implementierung:
|
|
||||||
if ($article->getAuthor() !== $author) {
|
|
||||||
throw new UnauthorizedAccessException("unauthorized_access");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$db = $this->getConnection();
|
|
||||||
|
|
||||||
$sql = "UPDATE articles
|
|
||||||
SET title = :title, content = :content, author = :author, category = :category, tags = :tags
|
|
||||||
WHERE id = :id;";
|
|
||||||
|
|
||||||
$command = $db->prepare($sql);
|
|
||||||
if (!$command) {
|
|
||||||
throw new InternalServerErrorException("internal_error");
|
|
||||||
}
|
|
||||||
|
|
||||||
$success = $command->execute([
|
|
||||||
":id" => $id,
|
|
||||||
":title" => $article->getTitle(),
|
|
||||||
":content" => $article->getContent(),
|
|
||||||
":author" => $author,
|
|
||||||
":category" => $article->getCategory(),
|
|
||||||
":tags" => $article->getTags()
|
|
||||||
]);
|
|
||||||
|
|
||||||
// rowCount() prüft, ob eine Zeile mit dieser ID existierte und geändert werden konnte
|
|
||||||
if (!$success || $command->rowCount() === 0) {
|
|
||||||
// Falls die ID nicht existiert, prüfen wir, ob sie überhaupt da ist
|
|
||||||
if (!$this->getArticle($id)) {
|
|
||||||
throw new NotFoundException("missing_id");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
throw new InternalServerErrorException("internal_error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function deleteArticle($id, $author)
|
|
||||||
{
|
|
||||||
$article = getArticle($id);
|
|
||||||
if (empty($article)) {
|
|
||||||
throw new NotFoundException("not_found_article");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Berechtigungsprüfung:
|
|
||||||
if ($article->getAuthor() !== $author) {
|
|
||||||
throw new UnauthorizedAccessException("unauthorized_access");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$db = $this->getConnection();
|
|
||||||
$sql = "DELETE FROM articles WHERE id = :id;";
|
|
||||||
|
|
||||||
$command = $db->prepare($sql);
|
|
||||||
if (!$command) {
|
|
||||||
throw new InternalServerErrorException("internal_error");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$command->execute([":id" => $id])) {
|
|
||||||
throw new InternalServerErrorException("internal_error");
|
|
||||||
}
|
|
||||||
} catch (PDOException $exc) {
|
|
||||||
throw new InternalServerErrorException("internal_error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getArticle($id)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$db = $this->getConnection();
|
|
||||||
$sql = "SELECT * FROM articles WHERE id = :id;";
|
|
||||||
|
|
||||||
$command = $db->prepare($sql);
|
|
||||||
if (!$command) {
|
|
||||||
throw new InternalServerErrorException("internal_error");
|
|
||||||
}
|
|
||||||
|
|
||||||
$command->execute([":id" => $id]);
|
|
||||||
$row = $command->fetch(PDO::FETCH_ASSOC);
|
|
||||||
|
|
||||||
if ($row) {
|
|
||||||
return new Article(
|
|
||||||
intval($row['id']),
|
|
||||||
$row['title'],
|
|
||||||
$row['content'],
|
|
||||||
$row['author'],
|
|
||||||
$row['category'],
|
|
||||||
$row['tags'],
|
|
||||||
$row['created']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
throw new InternalServerErrorException("internal_error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAllArticles()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$db = $this->getConnection();
|
|
||||||
$sql = "SELECT * FROM articles;";
|
|
||||||
|
|
||||||
$command = $db->query($sql);
|
|
||||||
if (!$command) {
|
|
||||||
throw new InternalServerErrorException("internal_error");
|
|
||||||
}
|
|
||||||
|
|
||||||
$rows = $command->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
$articles = [];
|
|
||||||
|
|
||||||
foreach ($rows as $row) {
|
|
||||||
$articles[] = new Article(
|
|
||||||
intval($row['id']),
|
|
||||||
$row['title'],
|
|
||||||
$row['content'],
|
|
||||||
$row['author'],
|
|
||||||
$row['category'],
|
|
||||||
$row['tags'],
|
|
||||||
$row['created']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $articles;
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
throw new InternalServerErrorException("internal_error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getArticlesByAuthor($author)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$db = $this->getConnection();
|
|
||||||
$sql = "SELECT * FROM articles WHERE author = :author;";
|
|
||||||
|
|
||||||
$command = $db->prepare($sql);
|
|
||||||
if (!$command) {
|
|
||||||
throw new InternalServerErrorException("internal_error");
|
|
||||||
}
|
|
||||||
|
|
||||||
$command->execute([":author" => $author]);
|
|
||||||
$rows = $command->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
$filteredArticles = [];
|
|
||||||
|
|
||||||
foreach ($rows as $row) {
|
|
||||||
$filteredArticles[] = new Article(
|
|
||||||
intval($row['id']),
|
|
||||||
$row['title'],
|
|
||||||
$row['content'],
|
|
||||||
$row['author'],
|
|
||||||
$row['category'],
|
|
||||||
$row['tags'],
|
|
||||||
$row['created']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $filteredArticles;
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
throw new InternalServerErrorException("internal_error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getArticlesByCategory($category)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$db = $this->getConnection();
|
|
||||||
$sql = "SELECT * FROM articles WHERE category = :category;";
|
|
||||||
|
|
||||||
$command = $db->prepare($sql);
|
|
||||||
if (!$command) {
|
|
||||||
throw new InternalServerErrorException("internal_error");
|
|
||||||
}
|
|
||||||
|
|
||||||
$command->execute([":category" => $category]);
|
|
||||||
$rows = $command->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
$filteredArticles = [];
|
|
||||||
|
|
||||||
foreach ($rows as $row) {
|
|
||||||
$filteredArticles[] = new Article(
|
|
||||||
intval($row['id']),
|
|
||||||
$row['title'],
|
|
||||||
$row['content'],
|
|
||||||
$row['author'],
|
|
||||||
$row['category'],
|
|
||||||
$row['tags'],
|
|
||||||
$row['created']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $filteredArticles;
|
|
||||||
} catch (PDOException $exc) {
|
|
||||||
throw new InternalServerErrorException("internal_error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function search(string $keyword): array
|
|
||||||
{
|
|
||||||
// TODO: implement search()
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,261 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
require_once "UserManagerDAO.php";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Klasse für den Zugriff auf Benutzerdaten über eine SQLite-Datenbank.
|
|
||||||
*
|
|
||||||
* Diese Klasse verwendet PDO, Prepared Statements und speichert
|
|
||||||
* Benutzerdaten in der Datei db/users.db.
|
|
||||||
*/
|
|
||||||
class DatabaseUserManager implements UserManagerDAO {
|
|
||||||
|
|
||||||
private static $instance = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Konstruktor.
|
|
||||||
*
|
|
||||||
* Erstellt die Benutzerdatenbank und die Tabelle users,
|
|
||||||
* falls diese noch nicht existieren.
|
|
||||||
*
|
|
||||||
* @throws RuntimeException wenn die Datenbank nicht erstellt werden kann
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$db = $this->getConnection();
|
|
||||||
|
|
||||||
$db->exec("
|
|
||||||
CREATE TABLE IF NOT EXISTS users (
|
|
||||||
email TEXT PRIMARY KEY,
|
|
||||||
vorname TEXT NOT NULL,
|
|
||||||
nachname TEXT NOT NULL,
|
|
||||||
password TEXT NOT NULL
|
|
||||||
);
|
|
||||||
");
|
|
||||||
|
|
||||||
unset($db);
|
|
||||||
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
throw new RuntimeException("Benutzerdatenbank konnte nicht erstellt werden.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Baut eine Verbindung zur SQLite-Datenbank auf.
|
|
||||||
*
|
|
||||||
* @return PDO Datenbankverbindung
|
|
||||||
*
|
|
||||||
* @throws RuntimeException wenn keine Verbindung hergestellt werden kann
|
|
||||||
*/
|
|
||||||
private function getConnection()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$dsn = 'sqlite:' . __DIR__ . '/../../db/users.db';
|
|
||||||
|
|
||||||
$db = new PDO($dsn, null, null);
|
|
||||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
||||||
|
|
||||||
return $db;
|
|
||||||
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
throw new RuntimeException("Verbindung zur Benutzerdatenbank fehlgeschlagen.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gibt die Singleton-Instanz des DatabaseUserManagers zurück.
|
|
||||||
*
|
|
||||||
* @return DatabaseUserManager Instanz des DatabaseUserManagers
|
|
||||||
*/
|
|
||||||
public static function getInstance()
|
|
||||||
{
|
|
||||||
if (self::$instance == null) {
|
|
||||||
self::$instance = new DatabaseUserManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::$instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sucht einen Benutzer anhand seiner E-Mail-Adresse.
|
|
||||||
*
|
|
||||||
* @param string $email E-Mail-Adresse des Benutzers
|
|
||||||
*
|
|
||||||
* @return array|null Benutzerdaten als Array oder null,
|
|
||||||
* wenn kein Benutzer gefunden wurde
|
|
||||||
*
|
|
||||||
* @throws RuntimeException wenn der Benutzer nicht geladen werden kann
|
|
||||||
*/
|
|
||||||
public function findUser($email)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$db = $this->getConnection();
|
|
||||||
|
|
||||||
$sql = "SELECT * FROM users WHERE email = :email";
|
|
||||||
$command = $db->prepare($sql);
|
|
||||||
|
|
||||||
$command->execute([
|
|
||||||
":email" => $email
|
|
||||||
]);
|
|
||||||
|
|
||||||
$user = $command->fetch(PDO::FETCH_ASSOC);
|
|
||||||
|
|
||||||
return $user ?: null;
|
|
||||||
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
throw new RuntimeException("Benutzer konnte nicht geladen werden.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fügt einen neuen Benutzer in die Datenbank ein.
|
|
||||||
*
|
|
||||||
* Die Speicherung erfolgt innerhalb einer Transaktion.
|
|
||||||
* Doppelte E-Mail-Adressen werden durch den Primary Key verhindert.
|
|
||||||
*
|
|
||||||
* @param string $email E-Mail-Adresse des Benutzers
|
|
||||||
* @param string $vorname Vorname des Benutzers
|
|
||||||
* @param string $nachname Nachname des Benutzers
|
|
||||||
* @param string $password Passwort-Hash des Benutzers
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException wenn die E-Mail-Adresse bereits verwendet wird
|
|
||||||
* @throws RuntimeException wenn der Benutzer nicht gespeichert werden kann
|
|
||||||
*/
|
|
||||||
public function addUser($email, $vorname, $nachname, $password)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$db = $this->getConnection();
|
|
||||||
$db->beginTransaction();
|
|
||||||
|
|
||||||
$sql = "
|
|
||||||
INSERT INTO users (email, vorname, nachname, password)
|
|
||||||
VALUES (:email, :vorname, :nachname, :password)
|
|
||||||
";
|
|
||||||
|
|
||||||
$command = $db->prepare($sql);
|
|
||||||
|
|
||||||
$command->execute([
|
|
||||||
":email" => $email,
|
|
||||||
":vorname" => $vorname,
|
|
||||||
":nachname" => $nachname,
|
|
||||||
":password" => $password
|
|
||||||
]);
|
|
||||||
|
|
||||||
$db->commit();
|
|
||||||
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
if (isset($db) && $db->inTransaction()) {
|
|
||||||
$db->rollBack();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($e->getCode() === "23000") {
|
|
||||||
throw new InvalidArgumentException("Diese E-Mail-Adresse wird bereits verwendet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new RuntimeException("Benutzer konnte nicht gespeichert werden.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Aktualisiert die Daten eines bestehenden Benutzers.
|
|
||||||
*
|
|
||||||
* Optional kann zusätzlich das Passwort geändert werden.
|
|
||||||
* Wenn kein neues Passwort übergeben wird, bleibt das alte Passwort erhalten.
|
|
||||||
*
|
|
||||||
* @param string $oldEmail Aktuelle E-Mail-Adresse des Benutzers
|
|
||||||
* @param string $newEmail Neue E-Mail-Adresse des Benutzers
|
|
||||||
* @param string $vorname Neuer Vorname des Benutzers
|
|
||||||
* @param string $nachname Neuer Nachname des Benutzers
|
|
||||||
* @param string|null $password Neues Passwort oder null
|
|
||||||
*
|
|
||||||
* @return bool true, wenn der Benutzer aktualisiert wurde,
|
|
||||||
* sonst false
|
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException wenn die neue E-Mail-Adresse bereits verwendet wird
|
|
||||||
* @throws RuntimeException wenn der Benutzer nicht aktualisiert werden kann
|
|
||||||
*/
|
|
||||||
public function updateUser($oldEmail, $newEmail, $vorname, $nachname, $password = null)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$db = $this->getConnection();
|
|
||||||
|
|
||||||
if (!empty($password)) {
|
|
||||||
$sql = "
|
|
||||||
UPDATE users
|
|
||||||
SET email = :newEmail,
|
|
||||||
vorname = :vorname,
|
|
||||||
nachname = :nachname,
|
|
||||||
password = :password
|
|
||||||
WHERE email = :oldEmail
|
|
||||||
";
|
|
||||||
|
|
||||||
$params = [
|
|
||||||
":newEmail" => $newEmail,
|
|
||||||
":vorname" => $vorname,
|
|
||||||
":nachname" => $nachname,
|
|
||||||
":password" => password_hash($password, PASSWORD_DEFAULT),
|
|
||||||
":oldEmail" => $oldEmail
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
$sql = "
|
|
||||||
UPDATE users
|
|
||||||
SET email = :newEmail,
|
|
||||||
vorname = :vorname,
|
|
||||||
nachname = :nachname
|
|
||||||
WHERE email = :oldEmail
|
|
||||||
";
|
|
||||||
|
|
||||||
$params = [
|
|
||||||
":newEmail" => $newEmail,
|
|
||||||
":vorname" => $vorname,
|
|
||||||
":nachname" => $nachname,
|
|
||||||
":oldEmail" => $oldEmail
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$command = $db->prepare($sql);
|
|
||||||
$command->execute($params);
|
|
||||||
|
|
||||||
return $command->rowCount() > 0;
|
|
||||||
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
if ($e->getCode() === "23000") {
|
|
||||||
throw new InvalidArgumentException("Diese E-Mail-Adresse wird bereits verwendet.");
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new RuntimeException("Benutzer konnte nicht aktualisiert werden.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Löscht einen Benutzer anhand seiner E-Mail-Adresse.
|
|
||||||
*
|
|
||||||
* @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 der Benutzer nicht gelöscht werden kann
|
|
||||||
*/
|
|
||||||
public function deleteUser($email)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$db = $this->getConnection();
|
|
||||||
|
|
||||||
$sql = "DELETE FROM users WHERE email = :email";
|
|
||||||
$command = $db->prepare($sql);
|
|
||||||
|
|
||||||
$command->execute([
|
|
||||||
":email" => $email
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $command->rowCount() > 0;
|
|
||||||
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
throw new RuntimeException("Benutzer konnte nicht gelöscht werden.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -102,18 +102,8 @@ class LocalArticleManager implements ArticleManagerDAO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteArticle($id, $author)
|
public function deleteArticle($id)
|
||||||
{
|
{
|
||||||
$article = getArticle($id);
|
|
||||||
if (empty($article)) {
|
|
||||||
throw new NotFoundException("not_found_article");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Berechtigungsprüfung:
|
|
||||||
if ($article->getAuthor() !== $author) {
|
|
||||||
throw new UnauthorizedAccessException("unauthorized_access");
|
|
||||||
}
|
|
||||||
|
|
||||||
$articles = $this->getAllArticles();
|
$articles = $this->getAllArticles();
|
||||||
$articleFound = false;
|
$articleFound = false;
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once "UserManagerDAO.php";
|
require_once "UserDAOInterface.php";
|
||||||
|
|
||||||
class LocalUserManager implements UserManagerDAO {
|
class LocalUserDAO implements UserDAOInterface {
|
||||||
|
|
||||||
private string $file = "data/users.json";
|
private string $file = "data/users.json";
|
||||||
|
|
||||||
public static function getInstance(){
|
|
||||||
// TODO: implement the getIsntance method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lädt alle Benutzer aus der JSON-Datei.
|
* Lädt alle Benutzer aus der JSON-Datei.
|
||||||
*
|
*
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
* Definiert die Methoden, die jede UserDAO-Implementierung
|
* Definiert die Methoden, die jede UserDAO-Implementierung
|
||||||
* bereitstellen muss.
|
* bereitstellen muss.
|
||||||
*/
|
*/
|
||||||
interface UserManagerDAO {
|
interface UserDAOInterface {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sucht einen Benutzer anhand seiner E-Mail-Adresse.
|
* Sucht einen Benutzer anhand seiner E-Mail-Adresse.
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
require_once "LocalUserManager.php";
|
|
||||||
require_once "DatabaseUserManager.php";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Zentrale Klasse für den Zugriff auf Benutzerdaten.
|
|
||||||
*
|
|
||||||
* Hier kann zwischen lokaler Speicherung und Datenbankspeicherung
|
|
||||||
* gewechselt werden.
|
|
||||||
*/
|
|
||||||
class UserManager {
|
|
||||||
|
|
||||||
public static function getInstance() {
|
|
||||||
$userManager = DatabaseUserManager::getInstance();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Dummy-User anlegen, falls er noch nicht existiert.
|
|
||||||
* Passwort: test123
|
|
||||||
*/
|
|
||||||
if ($userManager->findUser("mustermann@web.de") == null) {
|
|
||||||
$userManager->addUser(
|
|
||||||
"mustermann@web.de",
|
|
||||||
"Max",
|
|
||||||
"Mustermann",
|
|
||||||
password_hash("test12345", PASSWORD_DEFAULT)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $userManager;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
|
||||||
* Prüft, ob ein Vor- oder Nachname gültig ist.
|
|
||||||
*
|
|
||||||
* Erlaubt werden Buchstaben, Umlaute, Leerzeichen und Bindestriche.
|
|
||||||
* Die Länge muss zwischen 2 und 20 Zeichen liegen.
|
|
||||||
*
|
|
||||||
* @param string $name Zu prüfender Name
|
|
||||||
*
|
|
||||||
* @return bool true wenn der Name gültig ist, sonst false
|
|
||||||
*/
|
|
||||||
function userNameValidator($name)
|
function userNameValidator($name)
|
||||||
{
|
{
|
||||||
$name = trim($name);
|
$name = trim($name);
|
||||||
$namePattern = '/^[a-zA-ZäöüÄÖÜß\s-]{2,20}$/u';
|
$namePattern = '/^[a-zA-ZäöüÄÖÜß\s-]{2,50}$/u';
|
||||||
|
|
||||||
return preg_match($namePattern, $name) === 1;
|
return preg_match($namePattern, $name) === 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Prüft, ob eine E-Mail-Adresse gültig ist.
|
|
||||||
*
|
|
||||||
* Die E-Mail-Adresse muss dem Standardformat entsprechen
|
|
||||||
* und darf höchstens 100 Zeichen lang sein.
|
|
||||||
*
|
|
||||||
* @param string $email Zu prüfende E-Mail-Adresse
|
|
||||||
*
|
|
||||||
* @return bool true wenn die E-Mail-Adresse gültig ist, sonst false
|
|
||||||
*/
|
|
||||||
function userEmailValidator($email)
|
function userEmailValidator($email)
|
||||||
{
|
{
|
||||||
$email = trim($email);
|
$email = trim($email);
|
||||||
@@ -36,35 +16,13 @@ function userEmailValidator($email)
|
|||||||
&& mb_strlen($email) <= 100;
|
&& mb_strlen($email) <= 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Prüft, ob ein Passwort die Längenanforderungen erfüllt.
|
|
||||||
*
|
|
||||||
* Das Passwort muss zwischen 5 und 12 Zeichen lang sein.
|
|
||||||
*
|
|
||||||
* @param string $password Zu prüfendes Passwort
|
|
||||||
*
|
|
||||||
* @return bool true wenn das Passwort gültig ist, sonst false
|
|
||||||
*/
|
|
||||||
function userPasswordValidator($password)
|
function userPasswordValidator($password)
|
||||||
{
|
{
|
||||||
$zeichenAnzahl = mb_strlen($password);
|
$zeichenAnzahl = mb_strlen($password);
|
||||||
|
|
||||||
return $zeichenAnzahl >= 5 && $zeichenAnzahl <= 12;
|
return $zeichenAnzahl >= 8 && $zeichenAnzahl <= 72;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Prüft ein optionales Passwort.
|
|
||||||
*
|
|
||||||
* Ein leeres Passwort ist erlaubt und bedeutet,
|
|
||||||
* dass das bestehende Passwort unverändert bleibt.
|
|
||||||
* Falls ein Passwort angegeben wurde, wird es
|
|
||||||
* mit den normalen Passwortregeln geprüft.
|
|
||||||
*
|
|
||||||
* @param string|null $password Zu prüfendes Passwort
|
|
||||||
*
|
|
||||||
* @return bool true wenn das Passwort gültig oder leer ist,
|
|
||||||
* sonst false
|
|
||||||
*/
|
|
||||||
function userOptionalPasswordValidator($password)
|
function userOptionalPasswordValidator($password)
|
||||||
{
|
{
|
||||||
if (!isset($password) || $password === '') {
|
if (!isset($password) || $password === '') {
|
||||||
|
|||||||
Reference in New Issue
Block a user