2022-09-13 13:14:49 +00:00
|
|
|
<?php
|
|
|
|
namespace Misuzu;
|
|
|
|
|
2023-08-03 01:35:08 +00:00
|
|
|
use Misuzu\Auth\AuthTokenCookie;
|
|
|
|
|
2024-12-02 02:28:08 +00:00
|
|
|
if(!isset($msz) || !($msz instanceof \Misuzu\MisuzuContext))
|
|
|
|
die('Script must be called through the Misuzu route dispatcher.');
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
if($msz->authInfo->isLoggedIn) {
|
2023-08-03 01:35:08 +00:00
|
|
|
if(!CSRF::validateRequest()) {
|
|
|
|
Template::render('auth.logout');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
$tokenInfo = $msz->authInfo->tokenInfo;
|
|
|
|
$msz->authCtx->sessions->deleteSessions(sessionTokens: $tokenInfo->sessionToken);
|
2023-08-03 01:35:08 +00:00
|
|
|
|
|
|
|
$tokenBuilder = $tokenInfo->toBuilder();
|
|
|
|
$tokenBuilder->removeUserId();
|
|
|
|
$tokenBuilder->removeSessionToken();
|
|
|
|
$tokenBuilder->removeImpersonatedUserId();
|
2022-09-13 13:14:49 +00:00
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
$tokenInfo = $tokenBuilder->toInfo();
|
2024-12-02 02:28:08 +00:00
|
|
|
AuthTokenCookie::apply($msz->authCtx->createAuthTokenPacker()->pack($tokenInfo));
|
2022-09-13 13:14:49 +00:00
|
|
|
}
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
Tools::redirect($msz->urls->format('index'));;
|