Vor und Nachname separat speichern
This commit is contained in:
+48
-20
@@ -3,21 +3,22 @@ include_once 'php/controller/profile-controller.php';
|
||||
$user = $user ?? null;
|
||||
?>
|
||||
|
||||
<!--
|
||||
Content: Profil
|
||||
Inhalt: Das eigene Profil, wenn man angemeldet ist. Dort hat man die Möglichkeit seine Angaben zu ändern.
|
||||
-->
|
||||
|
||||
<main class="form-page">
|
||||
<div class="flexbox">
|
||||
<!-- Linke Spalte: Profildaten -->
|
||||
|
||||
<div class="container">
|
||||
<form>
|
||||
<label class="input-label">Name</label>
|
||||
<label class="input-label">Vorname</label>
|
||||
<input type="text"
|
||||
class="login-input"
|
||||
readonly
|
||||
value="<?php echo htmlspecialchars($user["username"] ?? ""); ?>">
|
||||
value="<?php echo htmlspecialchars($user["vorname"] ?? ""); ?>">
|
||||
|
||||
<label class="input-label">Nachname</label>
|
||||
<input type="text"
|
||||
class="login-input"
|
||||
readonly
|
||||
value="<?php echo htmlspecialchars($user["nachname"] ?? ""); ?>">
|
||||
|
||||
<label class="input-label">Email-Adresse</label>
|
||||
<input type="email"
|
||||
@@ -31,6 +32,7 @@ $user = $user ?? null;
|
||||
readonly
|
||||
value="********">
|
||||
</form>
|
||||
|
||||
<br>
|
||||
|
||||
<a href="index.php?pfad=deleteAccount" class="button">
|
||||
@@ -44,36 +46,53 @@ $user = $user ?? null;
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Rechte Spalte: Eigene Beiträge -->
|
||||
<div class="container">
|
||||
<h2 class="section-title">Meine Beiträge</h2>
|
||||
|
||||
<div class="articles-list">
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "internal_error"): ?>
|
||||
|
||||
<p class="alert-message is-error">
|
||||
Es ist ein interner Fehler aufgetreten. Bitte versuche es erneut.
|
||||
</p>
|
||||
|
||||
<?php elseif (isset($userArticles) && count($userArticles) > 0): ?>
|
||||
|
||||
<?php foreach ($userArticles as $userArticle): ?>
|
||||
<!-- Ein einzelner Artikel-Eintrag -->
|
||||
<div class="article-item">
|
||||
<div class="article-meta">
|
||||
<span class="article-date"><?php echo htmlspecialchars($userArticle->getCreationDate()); ?></span>
|
||||
<span class="article-category"><?php echo htmlspecialchars($userArticle->getCategory()); ?></span>
|
||||
<span class="article-date">
|
||||
<?php echo htmlspecialchars($userArticle->getCreationDate()); ?>
|
||||
</span>
|
||||
|
||||
<span class="article-category">
|
||||
<?php echo htmlspecialchars($userArticle->getCategory()); ?>
|
||||
</span>
|
||||
</div>
|
||||
<h3 class="article-title"><?php echo htmlspecialchars($userArticle->getTitle()); ?></h3>
|
||||
|
||||
<h3 class="article-title">
|
||||
<?php echo htmlspecialchars($userArticle->getTitle()); ?>
|
||||
</h3>
|
||||
|
||||
<?php
|
||||
$tags = $userArticle->getTags();
|
||||
if (isset($tags) && !empty($tags)): ?>
|
||||
if (isset($tags) && !empty($tags)):
|
||||
?>
|
||||
<div class="article-view-bottom-section">
|
||||
<div class="article-view-tags-label">Tags:</div>
|
||||
|
||||
<div class="article-view-tags-list">
|
||||
<?php
|
||||
$tagArray = is_array($tags) ? $tags : explode(',', $tags);
|
||||
|
||||
foreach ($tagArray as $tag):
|
||||
$trimmedTag = trim($tag);
|
||||
|
||||
if (!empty($trimmedTag)):
|
||||
?>
|
||||
<span class="article-view-tag-item"><?php echo htmlspecialchars($trimmedTag); ?></span>
|
||||
<span class="article-view-tag-item">
|
||||
<?php echo htmlspecialchars($trimmedTag); ?>
|
||||
</span>
|
||||
<?php
|
||||
endif;
|
||||
endforeach;
|
||||
@@ -81,18 +100,27 @@ $user = $user ?? null;
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<a href="index.php?pfad=updateArticle&id=<?php echo $userArticle->getID(); ?>" class="edit-link-button">Bearbeiten</a>
|
||||
|
||||
<a href="index.php?pfad=updateArticle&id=<?php echo $userArticle->getID(); ?>"
|
||||
class="edit-link-button">
|
||||
Bearbeiten
|
||||
</a>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<p>Du hast noch keine Beiträge erstellt.</p>
|
||||
<button type="button" class="button" onclick="window.location.href='index.php?pfad=createArticle';">
|
||||
|
||||
<button type="button"
|
||||
class="button"
|
||||
onclick="window.location.href='index.php?pfad=createArticle';">
|
||||
Beitrag erstellen!
|
||||
</button>
|
||||
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
unset($_SESSION["message"]);
|
||||
?>
|
||||
|
||||
<?php unset($_SESSION["message"]); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -4,10 +4,6 @@ include_once 'php/controller/register-controller.php';
|
||||
$error = $error ?? null;
|
||||
?>
|
||||
|
||||
<!--
|
||||
Form: Registrierung
|
||||
Funktion: Erstellung neuer Benutzerkonten
|
||||
-->
|
||||
<main class="login-page">
|
||||
<div class="login-container">
|
||||
|
||||
|
||||
@@ -12,11 +12,14 @@ if (!isset($_SESSION["user"])) {
|
||||
try {
|
||||
$dao = new LocalUserDAO();
|
||||
$user = $dao->findUser($_SESSION["user_email"] ?? "");
|
||||
|
||||
$articleManager = ArticleManager::getInstance();
|
||||
$userArticles = $articleManager->getArticlesByAuthor($_SESSION["user_email"]);
|
||||
if(!isset($userArticles)) {
|
||||
|
||||
if (!isset($userArticles)) {
|
||||
$_SESSION["message"] = "user_has_no_articles";
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
$_SESSION["message"] = "internal_error";
|
||||
exit();
|
||||
|
||||
@@ -5,10 +5,6 @@ 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"] ?? "";
|
||||
@@ -27,7 +23,8 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
|
||||
$dao->addUser(
|
||||
$email,
|
||||
$vorname . " " . $nachname,
|
||||
$vorname,
|
||||
$nachname,
|
||||
$password
|
||||
);
|
||||
|
||||
@@ -37,4 +34,4 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
require_once "UserDAOInterface.php";
|
||||
|
||||
class LocalUserDAO implements UserDAOInterface {
|
||||
@@ -28,6 +29,13 @@ class LocalUserDAO implements UserDAOInterface {
|
||||
|
||||
foreach ($users as $user) {
|
||||
if ($user["email"] === $email) {
|
||||
|
||||
if (!isset($user["vorname"]) && isset($user["username"])) {
|
||||
$nameParts = explode(" ", $user["username"], 2);
|
||||
$user["vorname"] = $nameParts[0] ?? "";
|
||||
$user["nachname"] = $nameParts[1] ?? "";
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
@@ -35,12 +43,13 @@ class LocalUserDAO implements UserDAOInterface {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function addUser($email, $username, $password) {
|
||||
public function addUser($email, $vorname, $nachname, $password) {
|
||||
$users = $this->loadUsers();
|
||||
|
||||
$users[] = [
|
||||
"email" => $email,
|
||||
"username" => $username,
|
||||
"vorname" => $vorname,
|
||||
"nachname" => $nachname,
|
||||
"password" => $password
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user