diff options
| author | Syndamia <kamen@syndamia.com> | 2025-02-02 13:16:00 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2025-02-02 13:16:00 +0200 |
| commit | 168abc2c8512343f2a65461c6791ae852ae64665 (patch) | |
| tree | 746732514621e854cdf7d27cb869aa85518e327a | |
| parent | 26b368ecc159886ae4122d2b31e307089077f0d3 (diff) | |
| download | nowayforward_human-168abc2c8512343f2a65461c6791ae852ae64665.tar nowayforward_human-168abc2c8512343f2a65461c6791ae852ae64665.tar.gz nowayforward_human-168abc2c8512343f2a65461c6791ae852ae64665.zip | |
feat: Make require_login return the user object if the token is valid
| -rw-r--r-- | views/global/router.php | 11 | ||||
| -rw-r--r-- | views/list/add/index.php | 5 | ||||
| -rw-r--r-- | views/list/delete/index.php | 5 | ||||
| -rw-r--r-- | views/list/update/index.php | 5 |
4 files changed, 14 insertions, 12 deletions
diff --git a/views/global/router.php b/views/global/router.php index 16e143e..2a02e22 100644 --- a/views/global/router.php +++ b/views/global/router.php @@ -64,11 +64,20 @@ function redirect(string $href) { exit; } -function require_login(string $redirect = '/login') { +function require_login(string $redirect = '/login') : Database\User { global $TOKEN; if ($TOKEN === '') { redirect($redirect); } + + $user = null; + try { + $user = Database\Cookie::fromDB($TOKEN); + } + catch (Exception $e) { + redirect($redirect); + } + return $user; } if (str_ends_with($view, '.php')) { diff --git a/views/list/add/index.php b/views/list/add/index.php index 98c768d..272efda 100644 --- a/views/list/add/index.php +++ b/views/list/add/index.php @@ -1,11 +1,10 @@ <?php - require_login(); - + $user = require_login(); $webpage = null; $list = null; try { - $list = Database\Cookie::fromDB($TOKEN)->archiveLists(); + $list = $user->archiveLists(); $webpage = Database\Webpage::fromDBwid($_GET['wid']); } catch (Exception $e) {} diff --git a/views/list/delete/index.php b/views/list/delete/index.php index 7d5bf5b..02eb37d 100644 --- a/views/list/delete/index.php +++ b/views/list/delete/index.php @@ -1,14 +1,11 @@ <?php - require_login(); - + $user = require_login(); $list = null; $author = null; - $user = null; try { $list = Database\ArchiveList::fromDB($_GET['lid'] ?? -1); $author = Database\User::fromDBuid($list->AuthorUID); - $user = Database\Cookie::fromDB($TOKEN); } catch(Exception $e) {} ?> diff --git a/views/list/update/index.php b/views/list/update/index.php index 9374aef..e8b562c 100644 --- a/views/list/update/index.php +++ b/views/list/update/index.php @@ -1,14 +1,11 @@ <?php - require_login(); - + $user = require_login(); $list = null; $author = null; - $user = null; try { $list = Database\ArchiveList::fromDB($_GET['lid'] ?? -1); $author = Database\User::fromDBuid($list->AuthorUID); - $user = Database\Cookie::fromDB($TOKEN); } catch(Exception $e) {} ?> |
