Benutzeranmeldungsfunktionlität
This commit is contained in:
parent
f59491a327
commit
3d246ccb60
@ -21,7 +21,6 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
margin: 10px;
|
|
||||||
color: var(--brand-white);
|
color: var(--brand-white);
|
||||||
font-size: var(--font-size-title-h1);
|
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(){
|
public function register(){
|
||||||
$this->db->createUser($_POST);
|
$this->db->createUser($_POST);
|
||||||
$this->view->setDoMethodName("showUserConfirmation");
|
$this->view->setDoMethodName("showUserRegisterConfirmation");
|
||||||
$this->showUserConfirmation();
|
$this->showUserRegisterConfirmation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function login(){
|
public function login(){
|
||||||
@ -43,13 +53,32 @@ class UserController{
|
|||||||
$hash = hash('sha256', $_POST["password"] . $user["salt"]);
|
$hash = hash('sha256', $_POST["password"] . $user["salt"]);
|
||||||
|
|
||||||
if($hash == $user["passwort"]){
|
if($hash == $user["passwort"]){
|
||||||
$_SESSION["user_id"] = $user["id"];
|
$this->setUserSession($user);
|
||||||
$_SESSION["user_role"] = $user["role"];
|
$this->showUserLoginConfirmation();
|
||||||
echo "Login ergolgreich";
|
|
||||||
}else{
|
}else{
|
||||||
echo "Falsches Passwort";
|
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 = $pdo->prepare($sql);
|
||||||
$sth->execute([
|
$sth->execute([
|
||||||
":guid" => $guid,
|
":guid" => $guid,
|
||||||
":name" => $values["name"],
|
":name" => $values["lastname"],
|
||||||
":firstname" => $values["lastname"],
|
":firstname" => $values["name"],
|
||||||
":email" => $values["email"],
|
":email" => $values["email"],
|
||||||
":password" => $hash,
|
":password" => $hash,
|
||||||
":salt" => $salt,
|
":salt" => $salt,
|
||||||
@ -51,4 +51,12 @@ class UserModel extends Database
|
|||||||
return $sth->fetch();
|
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