Skip to content

Commit

Permalink
Add dashboard.
Browse files Browse the repository at this point in the history
  • Loading branch information
lewmilburn committed Jun 11, 2024
1 parent 21edc2c commit 5dec27f
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 4 deletions.
17 changes: 17 additions & 0 deletions Processes/User/IsAuthenticated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace PeopleHive\Processes\User;

use Starlight\Session\Session;

class IsAuthenticated {
public function check(): bool
{
if (!isset($_SESSION['uuid']) || !isset($_SESSION['starlight_token'])) {
return false;
}

$session = new Session();
return $session->Verify($_SESSION['uuid'].'$'.date('Y-m-d'));
}
}
29 changes: 29 additions & 0 deletions Processes/User/UserInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace PeopleHive\Processes\User;

use Starlight\Database\SQL;

class UserInfo {
private SQL $sql;

public function __construct() {
$this->sql = new SQL(DB_HOST, DB_USER, DB_PASS, DB_NAME);
}

public function getRole(): int|bool
{
$Auth = new IsAuthenticated();

if ($Auth->Check()) {
$query = $this->sql->Query("SELECT `role` FROM `users` WHERE `uuid` = '" . $this->sql->Escape($_SESSION['uuid']) . "'");
if ($query->num_rows != 0) {
return $query->fetch_assoc()['role'];
} else {
return false;
}
} else {
return false;
}
}
}
6 changes: 3 additions & 3 deletions Router/Authenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace PeopleHive\Router;

use PeopleHive\Processes\User\IsAuthenticated;
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'))) {
$isAuth = new IsAuthenticated();
if ($isAuth->check()) {
$this->GET('/dashboard','/Views/Dashboard.php');
} else {
$this->GET('/dashboard','/Views/403.php');
Expand Down
54 changes: 53 additions & 1 deletion Views/Dashboard.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
<?php

var_dump($_SESSION);
use PeopleHive\Processes\User\UserInfo;

$UserInfo = new UserInfo();
$role = $UserInfo->getRole();

?><!DOCTYPE html>
<html lang="en">
<head>
<title><?= 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>
<h1>Dashboard</h1>
</header>

<main>
<p class="text-center">
Welcome to <?= WEBSITE_NAME; ?>'s HR Portal. Please select an option below to get started.
</p>

<br><br>

<div class="cards">
<a class="card-yellow" href="/profile">My Account</a>
<?php if ($role >= 1) { ?>
<a class="card-yellow" href="/dashboard/workplace">My Job</a>
<a class="card-yellow" href="/dashboard/documents">My Documents</a>
<a class="card-yellow" href="/dashboard/holidays">Holidays</a>
<?php } ?>
<a class="card-yellow" href="/jobs">Vacancies</a>
<?php if ($role >= 2) { ?>
<a class="card-yellow" href="/dashboard/jobs">Manage Vacancies</a>
<?php } if ($role >= 3) { ?>
<a class="card-yellow" href="/dashboard/company">My Company</a>
<?php } ?>
</div>

<br><br><hr><br><br>

<h2 class="text-center">About <?= WEBSITE_NAME; ?></h2>
<br>
<p>
<?= file_get_contents(__DIR__ . '/../Content/Text/ABOUT.txt'); ?>
</p>
</main>

<?php require_once __DIR__ . "/Include/Footer.php"; ?>
</body>
</html>
3 changes: 3 additions & 0 deletions autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
require_once __DIR__ . '/starlight/Security/CSRF.php';
require_once __DIR__ . '/starlight/Security/XSS.php';

require_once __DIR__ . '/Processes/User/IsAuthenticated.php';
require_once __DIR__ . '/Processes/User/UserInfo.php';

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

0 comments on commit 5dec27f

Please sign in to comment.