From c0499adae6f29b3f1c2463d9daaeca24a4ec4a5a Mon Sep 17 00:00:00 2001 From: arnold Date: Fri, 30 Aug 2024 16:13:53 +0200 Subject: [PATCH] Remove the crappy demo --- demo/includes/AuthStorage.php | 79 ----------------------------------- demo/includes/auth.php | 18 -------- demo/index.php | 47 --------------------- demo/login.php | 72 ------------------------------- demo/logout.php | 16 ------- 5 files changed, 232 deletions(-) delete mode 100644 demo/includes/AuthStorage.php delete mode 100644 demo/includes/auth.php delete mode 100644 demo/index.php delete mode 100644 demo/login.php delete mode 100644 demo/logout.php diff --git a/demo/includes/AuthStorage.php b/demo/includes/AuthStorage.php deleted file mode 100644 index fefdcfb..0000000 --- a/demo/includes/AuthStorage.php +++ /dev/null @@ -1,79 +0,0 @@ - 1, - 'username' => 'jackie', - 'hashedPassword' => '$2y$10$lVUeiphXLAm4pz6l7lF9i.6IelAqRxV4gCBu8GBGhCpaRb6o0qzUO', // jackie123 - 'role' => 1, // user - ], - [ - 'id' => 2, - 'username' => 'john', - 'hashedPassword' => '$2y$10$RU85KDMhbh8pDhpvzL6C5.kD3qWpzXARZBzJ5oJ2mFoW7Ren.apC2', // john123 - 'role' => 10, // admin - ], - ]; - - /** - * Fetch a user by ID. - */ - public function fetchUserById(string $id): ?Auth\UserInterface - { - foreach (self::USERS as $user) { - if ((string)$user['id'] === $id) { - return BasicUser::fromData($user); - } - } - - return null; - } - - /** - * Fetch a user by username - */ - public function fetchUserByUsername(string $username): ?Auth\UserInterface - { - foreach (self::USERS as $user) { - if ($user['username'] === $username) { - return BasicUser::fromData($user); - } - } - - return null; - } - - /** - * Fetch the context by ID. - */ - public function fetchContext(string $id) : ?Auth\ContextInterface - { - // Return null if this application doesn't work with teams or organizations for auth. - return null; - } - - /** - * Get the default context of the user. - */ - public function getContextForUser(Auth\UserInterface $user) : ?Auth\ContextInterface - { - return null; - } -} \ No newline at end of file diff --git a/demo/includes/auth.php b/demo/includes/auth.php deleted file mode 100644 index 7fef1e7..0000000 --- a/demo/includes/auth.php +++ /dev/null @@ -1,18 +0,0 @@ - 1, - 'admin' => 10, -]); - -$auth = new Auth($levels, new AuthStorage()); - -session_start(); -$auth->initialize(); - -return $auth; \ No newline at end of file diff --git a/demo/index.php b/demo/index.php deleted file mode 100644 index 8a3bceb..0000000 --- a/demo/index.php +++ /dev/null @@ -1,47 +0,0 @@ -setPsr4('', __DIR__ . '/includes'); - -/** @var Auth $auth */ -$auth = require __DIR__ . '/includes/auth.php'; - -if (!$auth->isLoggedIn()) { - header('Location: login.php', true, 307); - exit(); -} - -?> - - - - Jasny Auth demo - - - - - - - - - -
-

Jasny Auth demo

- -

- Logged in as user()->username ?> - is('admin')): ?>(admin) -

- - Logout -
- - diff --git a/demo/login.php b/demo/login.php deleted file mode 100644 index 21f0aa9..0000000 --- a/demo/login.php +++ /dev/null @@ -1,72 +0,0 @@ -setPsr4('', __DIR__ . '/includes'); - -/** @var Auth $auth */ -$auth = require __DIR__ . '/includes/auth.php'; - -// Handle POST request -if ($_SERVER['REQUEST_METHOD'] === 'POST') { - try { - $auth->login((string)($_POST['username'] ?? ''), (string)($_POST['password'] ?? '')); - } catch (LoginException $exception) { - $error = $exception->getMessage(); - } -} - -if ($auth->isLoggedIn()) { - header('Location: index.php', true, 307); - exit(); -} - -// Show the form in case of GET request -?> - - - - Login | Jasny Auth demo - - - - - - - - - -
-

Jasny Auth demo

- - -
- - -
- - - - - - - -
-
- - diff --git a/demo/logout.php b/demo/logout.php deleted file mode 100644 index 4adb5b3..0000000 --- a/demo/logout.php +++ /dev/null @@ -1,16 +0,0 @@ -setPsr4('', __DIR__ . '/includes'); - -/** @var Auth $auth */ -$auth = require __DIR__ . '/includes/auth.php'; - -$auth->logout(); - -header('Location: index.php', true, 307); -exit();