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) {
// @TODO // @TODO
// Auth // Auth
if (!session_id()) {
$_SESSION['username'] = $userName;
}
// Redirect // Redirect
header('Location: ' . PROJECT_HOST, true, 302);
} else { } else {

8
src/application/controller/logout.php

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

8
src/bootstrap.php

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

Loading…
Cancel
Save