add session-based aouth

This commit is contained in:
ghost 2021-12-29 01:07:39 +02:00
parent 1a3a832c0c
commit c1ea348200
4 changed files with 25 additions and 0 deletions

View File

@ -61,8 +61,13 @@ if (isset($_POST) && $_POST) {
// @TODO
// Auth
if (!session_id()) {
$_SESSION['username'] = $userName;
}
// Redirect
header('Location: ' . PROJECT_HOST, true, 302);
} else {

View File

@ -0,0 +1,8 @@
<?php
if (isset($_SESSION['username'])) {
session_destroy();
}
header('Location: ' . PROJECT_HOST, true, 302);

View File

@ -1,3 +1,7 @@
<?php
if (isset($_SESSION['username'])) {
header('Location: ' . PROJECT_HOST, true, 302);
}
require(PROJECT_DIR . '/application/view/register.phtml');

View File

@ -41,6 +41,11 @@ $_modelBlock = new ModelBlock(
DB_PASSWORD
);
// Start session
if (!session_id()) {
session_start();
}
// Route
if (isset($_GET['_route_'])) {
@ -51,6 +56,9 @@ if (isset($_GET['_route_'])) {
case 'login':
require(PROJECT_DIR . '/application/controller/login.php');
break;
case 'logout':
require(PROJECT_DIR . '/application/controller/logout.php');
break;
case 'register':
require(PROJECT_DIR . '/application/controller/register.php');
break;