<?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');
}

$apiTokenService = (new AuthServicesFactory())->createApiTokenService();
$count = $apiTokenService->revokeAllByAdmin();
Flash::success(sprintf(t('%d API tokens revoked'), $count), 'admin/settings', 'api_tokens_revoked');
Router::redirect('admin/settings');
