summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--localwebsite/classes/auth.php12
-rw-r--r--localwebsite/functions.php15
-rw-r--r--localwebsite/handlers/MiscHandler.php4
3 files changed, 22 insertions, 9 deletions
diff --git a/localwebsite/classes/auth.php b/localwebsite/classes/auth.php
index 2cdee72..a13843b 100644
--- a/localwebsite/classes/auth.php
+++ b/localwebsite/classes/auth.php
@@ -4,25 +4,19 @@ class auth {
public static ?User $authorizedUser = null;
- const SESSION_TIMEOUT = 86400 * 365;
- const COOKIE_NAME = 'auth';
+ const COOKIE_NAME = 'lws-auth';
public static function getToken(): ?string {
return $_COOKIE[self::COOKIE_NAME] ?? null;
}
public static function setToken(string $token) {
- setcookie(self::COOKIE_NAME,
- $token,
- time() + self::SESSION_TIMEOUT,
- '/',
- config::get('auth_cookie_host'),
- true);
+ setcookie_safe(self::COOKIE_NAME, $token);
}
public static function resetToken() {
if (!headers_sent())
- setcookie(self::COOKIE_NAME, null, -1, '/', config::get('auth_cookie_host'));
+ unsetcookie(self::COOKIE_NAME);
}
public static function id(bool $do_check = true): int {
diff --git a/localwebsite/functions.php b/localwebsite/functions.php
index 4757765..4693fc5 100644
--- a/localwebsite/functions.php
+++ b/localwebsite/functions.php
@@ -282,4 +282,19 @@ function from_camel_case(string $s): string {
}
}
return $buf;
+}
+
+function unsetcookie(string $name) {
+ global $config;
+ setcookie($name, null, -1, '/', $config['auth_cookie_host']);
+}
+
+function setcookie_safe(...$args) {
+ global $config;
+ if (!headers_sent()) {
+ if (count($args) == 2)
+ setcookie($args[0], $args[1], time()+86400+365, '/', $config['auth_cookie_host']);
+ else
+ setcookie(...$args);
+ }
} \ No newline at end of file
diff --git a/localwebsite/handlers/MiscHandler.php b/localwebsite/handlers/MiscHandler.php
index b7c312a..4d2e20a 100644
--- a/localwebsite/handlers/MiscHandler.php
+++ b/localwebsite/handlers/MiscHandler.php
@@ -67,6 +67,10 @@ class MiscHandler extends RequestHandler
$hls_host = config::get('cam_hls_host');
$hls_proto = config::get('cam_hls_proto');
+ $hls_key = config::get('cam_hls_access_key');
+ if ($hls_key)
+ setcookie_safe('hls_key', $hls_key);
+
$this->tpl->set([
'hls_host' => $hls_host,
'hls_proto' => $hls_proto,