86 lines
2.0 KiB
PHP
86 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Blog\Controller;
|
|
|
|
use Blog\Model\UserModel;
|
|
|
|
class UserController{
|
|
private $view;
|
|
private $db;
|
|
private $validData = array();
|
|
private $errors = array();
|
|
|
|
public function __construct($view){
|
|
$this->db = new UserModel();
|
|
$this->view = $view;
|
|
}
|
|
|
|
public function showUserRegisterForm(){
|
|
|
|
}
|
|
|
|
public function showUserRegisterConfirmation(){
|
|
|
|
}
|
|
|
|
public function showUserLoginForm(){
|
|
|
|
}
|
|
|
|
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("showUserRegisterConfirmation");
|
|
$this->showUserRegisterConfirmation();
|
|
}
|
|
|
|
public function login(){
|
|
$user = $this->db->getUserByEmail($_POST["email"]);
|
|
|
|
if(!$user){
|
|
echo "Benutzer nicht gefunden";
|
|
}
|
|
|
|
$hash = hash('sha256', $_POST["password"] . $user["salt"]);
|
|
|
|
if($hash == $user["passwort"]){
|
|
$this->setUserSession($user);
|
|
$this->showUserLoginConfirmation();
|
|
}else{
|
|
echo "Falsches Passwort";
|
|
}
|
|
}
|
|
|
|
public function setUserSession(array $user){
|
|
$_SESSION["user_id"] = $user["id"];
|
|
$_SESSION["user_role"] = $user["role"];
|
|
$_SESSION["vorname"] = $user["vorname"];
|
|
$_SESSION["name"] = $user["name"];
|
|
}
|
|
|
|
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;
|
|
}
|
|
} |