Benutzeranmeldungsfunktionlität
This commit is contained in:
parent
f59491a327
commit
3d246ccb60
@ -21,7 +21,6 @@ body {
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 10px;
|
||||
color: var(--brand-white);
|
||||
font-size: var(--font-size-title-h1);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
include dirname(__DIR__).'/header.phtml';
|
||||
?>
|
||||
|
||||
<h1>Sie haben sich erfolgreich registriert</h1>
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
include dirname(__DIR__).'/footer.phtml';
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user