<?php

use MintyPHP\Router;
use MintyPHP\Service\Access\PermissionService;
use MintyPHP\Service\Auth\AuthServicesFactory;
use MintyPHP\Support\Flash;
use MintyPHP\Support\Guard;

Guard::requireLogin();
Guard::requirePermission(PermissionService::SETTINGS_UPDATE);

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    Router::redirect('admin/settings');
}

$rememberMeService = (new AuthServicesFactory())->createRememberMeService();
$count = $rememberMeService->expireAllTokensByAdmin();
Flash::success(sprintf(t('%d login tokens expired'), $count), 'admin/settings', 'login_tokens_expired');
Router::redirect('admin/settings');
