Skip to content

Commit

Permalink
Proper authentication.
Browse files Browse the repository at this point in the history
  • Loading branch information
lewmilburn committed Jun 11, 2024
1 parent 324e69d commit 21edc2c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Processes/POST/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
}

$Auth = new Session();
$Auth->Login($info['uuid']);
$Auth->Login($info['uuid'].'$'.date('Y-m-d'));
$_SESSION['uuid'] = $info['uuid'];

header('Location: /dashboard');
exit;
Expand Down
17 changes: 17 additions & 0 deletions Router/Authenticated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace PeopleHive\Router;

use Starlight\HTTP\Router;
use Starlight\Session\Session;

class Authenticated extends Router {
public function register() {
$Auth = new Session();
if ($Auth->Verify($_SESSION['uuid'].'$'.date('Y-m-d'))) {
$this->GET('/dashboard','/Views/Dashboard.php');
} else {
$this->GET('/dashboard','/Views/403.php');
}
}
}
4 changes: 4 additions & 0 deletions Router/router.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

use PeopleHive\Router\Main;
use PeopleHive\Router\Authenticated;

$Main = new Main();
$Main->register();

$Authenticated = new Authenticated();
$Authenticated->register();
23 changes: 23 additions & 0 deletions Views/403.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Page not Found - <?= WEBSITE_NAME; ?></title>
<link rel="stylesheet" href="/Assets/CSS/Font.css" type="text/css">
<link rel="stylesheet" href="/Assets/CSS/Dist.css" type="text/css">
</head>
<body>
<?php require_once __DIR__ . "/Include/Nav.php"; ?>

<header class="bg-red-500 nobg">
<h1>Access Denied</h1>
</header>

<main>
<p class="text-center">
You don't have access to the requested page or resource.
</p>
</main>

<?php require_once __DIR__ . "/Include/Footer.php"; ?>
</body>
</html>
3 changes: 3 additions & 0 deletions Views/Dashboard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

var_dump($_SESSION);
1 change: 1 addition & 0 deletions autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require_once __DIR__ . '/starlight/Security/XSS.php';

require_once __DIR__ . '/Router/Main.php';
require_once __DIR__ . '/Router/Authenticated.php';
require_once __DIR__ . '/Router/router.php';

require_once __DIR__ . '/Views/404.php';

0 comments on commit 21edc2c

Please sign in to comment.