Merge branch 'Registrierung' into dev
This commit is contained in:
Generated
+1
-3
@@ -10,9 +10,7 @@
|
|||||||
<option name="highlightLevel" value="WARNING" />
|
<option name="highlightLevel" value="WARNING" />
|
||||||
<option name="transferred" value="true" />
|
<option name="transferred" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PhpProjectSharedConfiguration" php_language_level="7.0">
|
<component name="PhpProjectSharedConfiguration" php_language_level="8.5" />
|
||||||
<option name="suggestChangeDefaultLanguageLevel" value="false" />
|
|
||||||
</component>
|
|
||||||
<component name="PhpStanOptionsConfiguration">
|
<component name="PhpStanOptionsConfiguration">
|
||||||
<option name="transferred" value="true" />
|
<option name="transferred" value="true" />
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -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();
|
||||||
+33
-12
@@ -1,3 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
$error = $error ?? null;
|
||||||
|
?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Form: Login-Bereich
|
Form: Login-Bereich
|
||||||
Funktion: Benutzerauthentifizierung und Zugang zum eigenen Profil, Erstellen von Beiträgen, etc.
|
Funktion: Benutzerauthentifizierung und Zugang zum eigenen Profil, Erstellen von Beiträgen, etc.
|
||||||
@@ -7,26 +11,43 @@
|
|||||||
|
|
||||||
<h1>Bitte anmelden</h1>
|
<h1>Bitte anmelden</h1>
|
||||||
|
|
||||||
<form>
|
<?php if ($error): ?>
|
||||||
<label id ="inputEmail" class="screenreader-only">E-Mail Adresse / </label>
|
<p style="color:red;">
|
||||||
|
<?php echo htmlspecialchars($error); ?>
|
||||||
|
</p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<form method="post" action="index.php?pfad=login">
|
||||||
|
|
||||||
<p class="input-label">Benutzername/E-Mail-Adresse:</p>
|
<p class="input-label">Benutzername/E-Mail-Adresse:</p>
|
||||||
<input type="email" name="email" class="login-input" placeholder="E-Mail-Adresse" required autofocus>
|
<input type="email"
|
||||||
|
name="email"
|
||||||
|
class="login-input"
|
||||||
|
placeholder="E-Mail-Adresse"
|
||||||
|
required
|
||||||
|
autofocus>
|
||||||
|
|
||||||
<p class="input-label">Passwort:</p>
|
<p class="input-label">Passwort:</p>
|
||||||
<input type="password" name="password" class="login-input" placeholder="Passwort" required>
|
<input type="password"
|
||||||
|
name="password"
|
||||||
|
class="login-input"
|
||||||
|
placeholder="Passwort"
|
||||||
|
required>
|
||||||
|
|
||||||
<div class="checkbox-wrapper">
|
<button type="submit"
|
||||||
<label>
|
value="anmelden"
|
||||||
<input type="checkbox" name="remember-me" value="1"> angemeldet bleiben
|
name="loginSubmit"
|
||||||
</label>
|
class="login-button">
|
||||||
</div>
|
anmelden
|
||||||
|
</button>
|
||||||
<button type="submit" value="anmelden" name="loginSubmit" class="login-button">anmelden</button>
|
|
||||||
|
|
||||||
<div class="register-link">
|
<div class="register-link">
|
||||||
<a href="register.php">Noch keinen Account? Jetzt hier registrieren!</a>
|
<a href="index.php?pfad=register">
|
||||||
|
Noch keinen Account? Jetzt hier registrieren!
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
$_SESSION = [];
|
||||||
|
session_destroy();
|
||||||
|
|
||||||
|
header("Location: index.php");
|
||||||
|
exit();
|
||||||
+28
-29
@@ -1,46 +1,45 @@
|
|||||||
<!--
|
<?php
|
||||||
Content: Profil
|
include_once 'php/controller/profile-controller.php';
|
||||||
Inhalt: Das eigene Profil, wenn man angemeldet ist. Dort hat man die Möglichkeit seine Angaben zu ändern.
|
|
||||||
-->
|
$user = $user ?? null;
|
||||||
|
?>
|
||||||
|
|
||||||
<main class="form-page">
|
<main class="form-page">
|
||||||
|
|
||||||
<div class="form-container">
|
<div class="form-container">
|
||||||
|
|
||||||
|
<h1>Mein Profil</h1>
|
||||||
|
|
||||||
<form>
|
<form>
|
||||||
|
<label class="input-label">Name</label>
|
||||||
<label class="input-label">Vorname</label>
|
<input type="text"
|
||||||
|
class="login-input"
|
||||||
<input type="text" name="Vorname" class="login-input" required
|
readonly
|
||||||
placeholder="Vorname"
|
value="<?php echo htmlspecialchars($user["username"] ?? ""); ?>">
|
||||||
value="<?php //DB-Daten ?>">
|
|
||||||
|
|
||||||
<label class="input-label">Nachname</label>
|
|
||||||
<input type="text" name="Nachname" class="login-input" required
|
|
||||||
placeholder="Nachname"
|
|
||||||
value="<?php //DB-Daten ?>">
|
|
||||||
|
|
||||||
<label class="input-label">Email-Adresse</label>
|
<label class="input-label">Email-Adresse</label>
|
||||||
<input type="email" name="Email" class="login-input" required
|
<input type="email"
|
||||||
placeholder="mustermann@web.de"
|
class="login-input"
|
||||||
value="<?php //DB-Daten ?>">
|
readonly
|
||||||
|
value="<?php echo htmlspecialchars($user["email"] ?? ""); ?>">
|
||||||
|
|
||||||
<label class="input-label">Passwort</label>
|
<label class="input-label">Passwort</label>
|
||||||
<input type="password" name="Passwort" class="login-input"
|
<input type="password"
|
||||||
required placeholder="Passwort">
|
class="login-input"
|
||||||
|
readonly
|
||||||
|
value="********">
|
||||||
|
</form>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
<button type="submit" class="login-button">
|
<a href="index.php?pfad=deleteAccount" class="login-button">
|
||||||
Speichern
|
Account löschen
|
||||||
</button>
|
</a>
|
||||||
|
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
<button type="button" class="login-button">
|
<a href="index.php?pfad=logout" class="login-button">
|
||||||
Account löschen
|
Abmelden
|
||||||
</button>
|
</a>
|
||||||
|
|
||||||
</form>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
+41
-11
@@ -1,3 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
include_once 'php/controller/register-controller.php';
|
||||||
|
|
||||||
|
$error = $error ?? null;
|
||||||
|
?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Form: Registrierung
|
Form: Registrierung
|
||||||
Funktion: Erstellung neuer Benutzerkonten
|
Funktion: Erstellung neuer Benutzerkonten
|
||||||
@@ -7,26 +13,50 @@
|
|||||||
|
|
||||||
<h1>Jetzt Registrieren!</h1>
|
<h1>Jetzt Registrieren!</h1>
|
||||||
|
|
||||||
<form>
|
<?php if ($error): ?>
|
||||||
|
<p style="color:red;">
|
||||||
|
<?php echo htmlspecialchars($error); ?>
|
||||||
|
</p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<form method="post" action="index.php?pfad=register">
|
||||||
|
|
||||||
<p class="input-label">Email:</p>
|
<p class="input-label">Email:</p>
|
||||||
<input type="email" name="email" class="login-input" placeholder="mustermann@web.de" required>
|
<input type="email"
|
||||||
|
name="email"
|
||||||
|
class="login-input"
|
||||||
|
placeholder="mustermann@web.de"
|
||||||
|
required>
|
||||||
|
|
||||||
<p class="input-label">Vorname:</p>
|
<p class="input-label">Vorname:</p>
|
||||||
<input type="text" name="vorname" class="login-input" placeholder="Max" required>
|
<input type="text"
|
||||||
|
name="vorname"
|
||||||
|
class="login-input"
|
||||||
|
placeholder="Max"
|
||||||
|
required>
|
||||||
|
|
||||||
<p class="input-label">Nachname:</p>
|
<p class="input-label">Nachname:</p>
|
||||||
<input type="text" name="nachname" class="login-input" placeholder="Mustermann" required>
|
<input type="text"
|
||||||
|
name="nachname"
|
||||||
|
class="login-input"
|
||||||
|
placeholder="Mustermann"
|
||||||
|
required>
|
||||||
|
|
||||||
<p class="input-label">Passwort:</p>
|
<p class="input-label">Passwort:</p>
|
||||||
<input type="password" name="password" class="login-input" placeholder="Passwort" required>
|
<input type="password"
|
||||||
|
name="password"
|
||||||
|
class="login-input"
|
||||||
|
placeholder="Passwort"
|
||||||
|
required>
|
||||||
|
|
||||||
<div class="checkbox-wrapper">
|
<button type="submit"
|
||||||
<label>
|
value="register"
|
||||||
<input type="checkbox" value="remember-me"> angemeldet bleiben
|
name="registerSubmit"
|
||||||
</label>
|
class="login-button">
|
||||||
</div>
|
kostenlos registrieren
|
||||||
|
</button>
|
||||||
|
|
||||||
<button type="submit" value="anmelden" name="loginSubmit" class="login-button">kostenlos registrieren</button>
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
[]
|
||||||
+53
-10
@@ -1,3 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Globales Menü, wird via PHP später in alle Seiten eingebunden
|
Globales Menü, wird via PHP später in alle Seiten eingebunden
|
||||||
-->
|
-->
|
||||||
@@ -11,17 +15,27 @@ Globales Menü, wird via PHP später in alle Seiten eingebunden
|
|||||||
<!-- Mobile navbar mit Burger-Symbol -->
|
<!-- Mobile navbar mit Burger-Symbol -->
|
||||||
<input type="checkbox" id="nav-toggle" class="nav__checkbox">
|
<input type="checkbox" id="nav-toggle" class="nav__checkbox">
|
||||||
<label for="nav-toggle" id="mobile-nav">
|
<label for="nav-toggle" id="mobile-nav">
|
||||||
<span>☰</span> <!-- Burger Icon Symbol -->
|
<span>☰</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<ul id="mobile-nav" class="nav__mobile-menu">
|
<ul id="mobile-nav" class="nav__mobile-menu">
|
||||||
<li>
|
<li>
|
||||||
<label for="nav-toggle" class="nav__close-btn">×</label>
|
<label for="nav-toggle" class="nav__close-btn">×</label>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<?php if (isset($_SESSION['user'])): ?>
|
||||||
|
|
||||||
<li><a href="index.php?pfad=profile">Profil</a></li>
|
<li><a href="index.php?pfad=profile">Profil</a></li>
|
||||||
|
<li><a href="index.php?pfad=logout">Abmelden</a></li>
|
||||||
|
<li><a href="index.php?pfad=createArticle">Beitrag erstellen</a></li>
|
||||||
|
|
||||||
|
<?php else: ?>
|
||||||
|
|
||||||
<li><a href="index.php?pfad=login">Anmelden</a></li>
|
<li><a href="index.php?pfad=login">Anmelden</a></li>
|
||||||
<li><a href="index.php?pfad=register">Registrieren</a></li>
|
<li><a href="index.php?pfad=register">Registrieren</a></li>
|
||||||
<li><a href="index.php?pfad=createArticle">Beitrag erstellen</a></li>
|
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<label class="nav__mobile-label">Sprachen</label>
|
<label class="nav__mobile-label">Sprachen</label>
|
||||||
<ul class="nav__mobile-submenu">
|
<ul class="nav__mobile-submenu">
|
||||||
@@ -39,7 +53,7 @@ Globales Menü, wird via PHP später in alle Seiten eingebunden
|
|||||||
<li><a href="index.php?pfad=mathe">Mathematik</a></li>
|
<li><a href="index.php?pfad=mathe">Mathematik</a></li>
|
||||||
<li><a href="index.php?pfad=biologie">Biologie</a></li>
|
<li><a href="index.php?pfad=biologie">Biologie</a></li>
|
||||||
<li><a href="index.php?pfad=chemie">Chemie</a></li>
|
<li><a href="index.php?pfad=chemie">Chemie</a></li>
|
||||||
<li><a href="index.php?pfad=englisch">Physik</a></li>
|
<li><a href="index.php?pfad=physik">Physik</a></li>
|
||||||
<li><a href="index.php?pfad=informatik">Informatik</a></li>
|
<li><a href="index.php?pfad=informatik">Informatik</a></li>
|
||||||
<li><a href="index.php?pfad=astronomie">Astronomie</a></li>
|
<li><a href="index.php?pfad=astronomie">Astronomie</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -85,6 +99,7 @@ Globales Menü, wird via PHP später in alle Seiten eingebunden
|
|||||||
<a href="index.php?pfad=literatur">Literatur</a>
|
<a href="index.php?pfad=literatur">Literatur</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="nav__item nav__dropdown">
|
<div class="nav__item nav__dropdown">
|
||||||
<button class="nav__dropdown-toggle">MINT</button>
|
<button class="nav__dropdown-toggle">MINT</button>
|
||||||
<div class="nav__dropdown-menu">
|
<div class="nav__dropdown-menu">
|
||||||
@@ -96,6 +111,7 @@ Globales Menü, wird via PHP später in alle Seiten eingebunden
|
|||||||
<a href="index.php?pfad=astronomie">Astronomie</a>
|
<a href="index.php?pfad=astronomie">Astronomie</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="nav__item nav__dropdown">
|
<div class="nav__item nav__dropdown">
|
||||||
<button class="nav__dropdown-toggle">Gesellschaft & Werte</button>
|
<button class="nav__dropdown-toggle">Gesellschaft & Werte</button>
|
||||||
<div class="nav__dropdown-menu">
|
<div class="nav__dropdown-menu">
|
||||||
@@ -112,6 +128,7 @@ Globales Menü, wird via PHP später in alle Seiten eingebunden
|
|||||||
<a href="index.php?pfad=theater">Theater</a>
|
<a href="index.php?pfad=theater">Theater</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="nav__item nav__dropdown">
|
<div class="nav__item nav__dropdown">
|
||||||
<button class="nav__dropdown-toggle">Technik & Praxis</button>
|
<button class="nav__dropdown-toggle">Technik & Praxis</button>
|
||||||
<div class="nav__dropdown-menu">
|
<div class="nav__dropdown-menu">
|
||||||
@@ -124,14 +141,40 @@ Globales Menü, wird via PHP später in alle Seiten eingebunden
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="nav__right">
|
<div class="nav__right">
|
||||||
<a href="index.php?pfad=profile" class="nav_item nav__link">Profil</a>
|
|
||||||
|
<?php if (isset($_SESSION['user'])): ?>
|
||||||
|
|
||||||
|
<a href="index.php?pfad=profile" class="nav__item nav__link">
|
||||||
|
Profil
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="index.php?pfad=createArticle" class="nav__item nav__button">
|
||||||
|
Beitrag erstellen
|
||||||
|
</a>
|
||||||
|
|
||||||
<div class="nav__search">
|
<div class="nav__search">
|
||||||
<?php
|
<?php include_once 'search.php'; ?>
|
||||||
include_once 'search.php';
|
|
||||||
?>
|
|
||||||
</div>
|
</div>
|
||||||
<a href="index.php?pfad=login" class="nav__item nav__button">Anmelden</a>
|
|
||||||
<a href="index.php?pfad=register" class="nav__item nav__button">Registrieren</a>
|
<a href="index.php?pfad=logout" class="nav__item nav__button">
|
||||||
<a href="index.php?pfad=createArticle" class="nav__item nav__button">Beitrag erstellen</a>
|
Abmelden
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<?php else: ?>
|
||||||
|
|
||||||
|
<div class="nav__search">
|
||||||
|
<?php include_once 'search.php'; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<a href="index.php?pfad=login" class="nav__item nav__button">
|
||||||
|
Anmelden
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="index.php?pfad=register" class="nav__item nav__button">
|
||||||
|
Registrieren
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
@@ -1,10 +1,30 @@
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
if (!isset($abs_path)) {
|
ob_start();
|
||||||
require_once "path.php";
|
|
||||||
|
$pfad = $_GET["pfad"] ?? "home";
|
||||||
|
|
||||||
|
/*
|
||||||
|
Controller für Aktionen werden vor der HTML-Ausgabe geladen,
|
||||||
|
damit Weiterleitungen mit header() funktionieren.
|
||||||
|
*/
|
||||||
|
if ($pfad === "login") {
|
||||||
|
include_once "php/controller/login-controller.php";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($pfad === "register") {
|
||||||
|
include_once "php/controller/register-controller.php";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($pfad === "logout") {
|
||||||
|
include_once "content/logout.php";
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($pfad === "deleteAccount") {
|
||||||
|
include_once "content/deleteAccount.php";
|
||||||
|
exit();
|
||||||
}
|
}
|
||||||
require_once $abs_path . "/php/controller/index-controller.php";
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
@@ -23,29 +43,29 @@ require_once $abs_path . "/php/controller/index-controller.php";
|
|||||||
<link rel="stylesheet" href="css/main.css">
|
<link rel="stylesheet" href="css/main.css">
|
||||||
<link rel="stylesheet" href="css/navbar.css">
|
<link rel="stylesheet" href="css/navbar.css">
|
||||||
<link rel="stylesheet" href="css/footer.css">
|
<link rel="stylesheet" href="css/footer.css">
|
||||||
<link rel="stylesheet" href="css/search-results.css">
|
|
||||||
<link rel="stylesheet" href="css/createArticle.css">
|
|
||||||
<link rel="stylesheet" href="css/showArticle.css">
|
|
||||||
<link rel="stylesheet" href="css/message.css">
|
|
||||||
<title>EduForge</title>
|
<title>EduForge</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
include_once 'includes/navbar.php';
|
include_once 'includes/navbar.php';
|
||||||
//Dynamischer Inhalt:
|
|
||||||
if (isset($_GET["pfad"])) {
|
|
||||||
if (file_exists($abs_path . '/content/' . $_GET["pfad"] . '.php')) {
|
|
||||||
include_once $abs_path . '/content/' . $_GET["pfad"] . '.php';
|
|
||||||
} else {
|
|
||||||
include_once $abs_path . '/content/404.php';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
include_once $abs_path . '/content/home.php';
|
|
||||||
}
|
|
||||||
include_once $abs_path . '/includes/footer.php';
|
|
||||||
?>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Dynamischer Inhalt:
|
||||||
|
Je nach pfad-Parameter wird die passende Datei aus content geladen.
|
||||||
|
*/
|
||||||
|
if (file_exists('content/' . $pfad . '.php')) {
|
||||||
|
include_once 'content/' . $pfad . '.php';
|
||||||
|
} else {
|
||||||
|
include_once 'content/404.php';
|
||||||
|
}
|
||||||
|
include_once 'includes/footer.php';
|
||||||
|
?>
|
||||||
|
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
ob_end_flush();
|
||||||
|
?>
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once "php/model/LocalUserDAO.php";
|
||||||
|
|
||||||
|
$dao = new LocalUserDAO();
|
||||||
|
$error = null;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Verarbeitung des Login-Formulars
|
||||||
|
Funktion: Prüft Benutzerdaten und erstellt Session für eingeloggten Nutzer
|
||||||
|
*/
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||||
|
|
||||||
|
$email = $_POST["email"] ?? "";
|
||||||
|
$password = $_POST["password"] ?? "";
|
||||||
|
|
||||||
|
$user = $dao->findUser($email);
|
||||||
|
|
||||||
|
if ($user && password_verify($password, $user["password"])) {
|
||||||
|
|
||||||
|
$_SESSION["user"] = $user["username"];
|
||||||
|
$_SESSION["user_email"] = $user["email"];
|
||||||
|
|
||||||
|
header("Location: index.php");
|
||||||
|
exit();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$error = "Login fehlgeschlagen. Bitte überprüfe deine Eingaben.";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once "php/model/LocalUserDAO.php";
|
||||||
|
|
||||||
|
$dao = new LocalUserDAO();
|
||||||
|
|
||||||
|
if (!isset($_SESSION["user"])) {
|
||||||
|
header("Location: index.php?pfad=login");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $dao->findUser($_SESSION["user_email"] ?? "");
|
||||||
|
|
||||||
|
if (!$user) {
|
||||||
|
$_SESSION = [];
|
||||||
|
session_destroy();
|
||||||
|
|
||||||
|
header("Location: index.php?pfad=login");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once "php/model/LocalUserDAO.php";
|
||||||
|
|
||||||
|
$dao = new LocalUserDAO();
|
||||||
|
$error = null;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Verarbeitung des Registrierungs-Formulars
|
||||||
|
Funktion: Erstellt neuen Benutzer und speichert ihn im DAO + Session
|
||||||
|
*/
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||||
|
|
||||||
|
$email = $_POST["email"] ?? "";
|
||||||
|
$vorname = $_POST["vorname"] ?? "";
|
||||||
|
$nachname = $_POST["nachname"] ?? "";
|
||||||
|
$password = password_hash(
|
||||||
|
$_POST["password"] ?? "",
|
||||||
|
PASSWORD_DEFAULT
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($dao->findUser($email)) {
|
||||||
|
|
||||||
|
$error = "Diese E-Mail-Adresse ist bereits registriert.";
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$dao->addUser(
|
||||||
|
$email,
|
||||||
|
$vorname . " " . $nachname,
|
||||||
|
$password
|
||||||
|
);
|
||||||
|
|
||||||
|
$_SESSION["user"] = $vorname . " " . $nachname;
|
||||||
|
$_SESSION["user_email"] = $email;
|
||||||
|
|
||||||
|
header("Location: index.php");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
require_once "UserDAOInterface.php";
|
||||||
|
|
||||||
|
class LocalUserDAO implements UserDAOInterface {
|
||||||
|
|
||||||
|
private string $file = "data/users.json";
|
||||||
|
|
||||||
|
private function loadUsers() {
|
||||||
|
if (!file_exists($this->file)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$json = file_get_contents($this->file);
|
||||||
|
$users = json_decode($json, true);
|
||||||
|
|
||||||
|
return is_array($users) ? $users : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function saveUsers($users) {
|
||||||
|
file_put_contents(
|
||||||
|
$this->file,
|
||||||
|
json_encode($users, JSON_PRETTY_PRINT)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findUser($email) {
|
||||||
|
$users = $this->loadUsers();
|
||||||
|
|
||||||
|
foreach ($users as $user) {
|
||||||
|
if ($user["email"] === $email) {
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addUser($email, $username, $password) {
|
||||||
|
$users = $this->loadUsers();
|
||||||
|
|
||||||
|
$users[] = [
|
||||||
|
"email" => $email,
|
||||||
|
"username" => $username,
|
||||||
|
"password" => $password
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->saveUsers($users);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteUser($email) {
|
||||||
|
$users = $this->loadUsers();
|
||||||
|
|
||||||
|
foreach ($users as $i => $user) {
|
||||||
|
if ($user["email"] === $email) {
|
||||||
|
unset($users[$i]);
|
||||||
|
$users = array_values($users);
|
||||||
|
$this->saveUsers($users);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface für den Zugriff auf Benutzerdaten.
|
||||||
|
*
|
||||||
|
* Definiert die Methoden, die jede UserDAO-Implementierung
|
||||||
|
* bereitstellen muss.
|
||||||
|
*/
|
||||||
|
interface UserDAOInterface {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sucht einen Benutzer anhand seiner E-Mail-Adresse.
|
||||||
|
*
|
||||||
|
* @param string $email E-Mail-Adresse des gesuchten Benutzers
|
||||||
|
* @return array|null Benutzerdaten als Array oder null
|
||||||
|
*/
|
||||||
|
public function findUser($email);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fügt einen neuen Benutzer hinzu.
|
||||||
|
*
|
||||||
|
* @param string $email E-Mail-Adresse des Benutzers
|
||||||
|
* @param string $username Benutzername des Benutzers
|
||||||
|
* @param string $password Passwort des Benutzers
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function addUser($email, $username, $password);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public function deleteUser($email);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user