Browse Source

add session-based aouth

main
ghost 3 years ago
parent
commit
c1ea348200
  1. 5
      src/application/controller/login.php
  2. 8
      src/application/controller/logout.php
  3. 4
      src/application/controller/register.php
  4. 8
      src/bootstrap.php

5
src/application/controller/login.php

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

8
src/application/controller/logout.php

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

4
src/application/controller/register.php

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

8
src/bootstrap.php

@ -41,6 +41,11 @@ $_modelBlock = new ModelBlock( @@ -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_'])) { @@ -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;

Loading…
Cancel
Save