adasdsa
This commit is contained in:
48
src/App/AuthStatusRedirect.php
Normal file
48
src/App/AuthStatusRedirect.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App;
|
||||
|
||||
final class AuthStatusRedirect
|
||||
{
|
||||
private const COOKIE_NAME = 'desktop_auth_status_redirect';
|
||||
|
||||
public static function set(string $target): void
|
||||
{
|
||||
if ($target === '' || !str_starts_with($target, '/')) {
|
||||
return;
|
||||
}
|
||||
|
||||
setcookie(self::COOKIE_NAME, $target, [
|
||||
'expires' => time() + 180,
|
||||
'path' => '/',
|
||||
'httponly' => true,
|
||||
'samesite' => 'Lax',
|
||||
]);
|
||||
}
|
||||
|
||||
public static function consume(): ?string
|
||||
{
|
||||
$target = trim((string) ($_COOKIE[self::COOKIE_NAME] ?? ''));
|
||||
|
||||
self::clear();
|
||||
|
||||
if ($target === '' || !str_starts_with($target, '/')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
||||
public static function clear(): void
|
||||
{
|
||||
setcookie(self::COOKIE_NAME, '', [
|
||||
'expires' => time() - 3600,
|
||||
'path' => '/',
|
||||
'httponly' => true,
|
||||
'samesite' => 'Lax',
|
||||
]);
|
||||
unset($_COOKIE[self::COOKIE_NAME]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user