change auth cookie and some related hls stuff
This commit is contained in:
parent
cf0b9f036b
commit
f1276e23d8
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user