This commit is contained in:
Karol Bielski 2025-06-25 10:19:06 +02:00
commit 5155284226
5 changed files with 62 additions and 9 deletions

View File

@ -20,7 +20,6 @@ body {
}
h1 {
margin: 10px;
color: var(--brand-white);
font-size: var(--font-size-title-h1);
}

View File

@ -19,7 +19,7 @@ class UserController{
}
public function showUserConfirmation(){
public function showUserRegisterConfirmation(){
}
@ -27,10 +27,20 @@ class UserController{
}
public function showUserLoginConfirmation(){
$userId = $this->getCurrentUserId();
$user = null;
var_dump($user . "user");
if($userId){
$user = $this->db->getUserById($userId);
}
include 'Views/User/showUserLoginConfirmation.phtml';
}
public function register(){
$this->db->createUser($_POST);
$this->view->setDoMethodName("showUserConfirmation");
$this->showUserConfirmation();
$this->view->setDoMethodName("showUserRegisterConfirmation");
$this->showUserRegisterConfirmation();
}
public function login(){
@ -43,13 +53,32 @@ class UserController{
$hash = hash('sha256', $_POST["password"] . $user["salt"]);
if($hash == $user["passwort"]){
$_SESSION["user_id"] = $user["id"];
$_SESSION["user_role"] = $user["role"];
echo "Login ergolgreich";
$this->setUserSession($user);
$this->showUserLoginConfirmation();
}else{
echo "Falsches Passwort";
}
}
public function setUserSession(array $user){
$_SESSION["user_id"] = $user["id"];
$_SESSION["user_role"] = $user["role"];
}
public function clearUserSession(){
unset($_SESSION["user_id"], $_SESSION["user_role"]);
}
public function logout(){
$this->clearUserSession();
echo "Erfolgreich ausgeloggt";
}
public function isUserLoggenIn(){
return isset($_SESSION["user_id"]);
}
public function getCurrentUserId(){
return $_SESSION["user_id"] ?? null;
}
}

View File

@ -28,8 +28,8 @@ class UserModel extends Database
$sth = $pdo->prepare($sql);
$sth->execute([
":guid" => $guid,
":name" => $values["name"],
":firstname" => $values["lastname"],
":name" => $values["lastname"],
":firstname" => $values["name"],
":email" => $values["email"],
":password" => $hash,
":salt" => $salt,
@ -51,4 +51,12 @@ class UserModel extends Database
return $sth->fetch();
}
public function getUserById($id){
$pdo = $this->linkDB();
$sql = "SELECT * FROM user WHERE id = :id";
$sth = $pdo->prepare($sql);
$sth->execute([":id" => $id]);
return $sth->fetch();
}
}

View File

@ -0,0 +1,17 @@
<?php
include dirname(__DIR__).'/header.phtml';
?>
<?php if ($user): ?>
<p>Hallo, <?= htmlspecialchars($user['vorname']) ?> <?= htmlspecialchars($user['name']) ?>!</p>
<?php else: ?>
<p>Benutzerdaten konnten nicht geladen werden.</p>
<?php endif; ?>
<h1>Sie haben sich erfolgreich angemeldet</h1>
<?php
include dirname(__DIR__).'/footer.phtml';
?>