aboutsummaryrefslogtreecommitdiff
path: root/views/global/router.php
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2025-02-02 13:16:00 +0200
committerSyndamia <kamen@syndamia.com>2025-02-02 13:16:00 +0200
commit168abc2c8512343f2a65461c6791ae852ae64665 (patch)
tree746732514621e854cdf7d27cb869aa85518e327a /views/global/router.php
parent26b368ecc159886ae4122d2b31e307089077f0d3 (diff)
downloadnowayforward_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
Diffstat (limited to 'views/global/router.php')
-rw-r--r--views/global/router.php11
1 files changed, 10 insertions, 1 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')) {