|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * The Session Keepalive Controller |
| 5 | + * |
| 6 | + * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 7 | + * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 8 | + * obtain one at https://mozilla.org/MPL/2.0/. |
| 9 | + * |
| 10 | + * @package phpMyFAQ |
| 11 | + * @author Thorsten Rinne <[email protected]> |
| 12 | + * @copyright 2024 phpMyFAQ Team |
| 13 | + * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
| 14 | + * @link https://www.phpmyfaq.de |
| 15 | + * @since 2024-11-23 |
| 16 | + */ |
| 17 | + |
| 18 | +declare(strict_types=1); |
| 19 | + |
| 20 | +namespace phpMyFAQ\Controller\Administration; |
| 21 | + |
| 22 | +use phpMyFAQ\Core\Exception; |
| 23 | +use phpMyFAQ\Filter; |
| 24 | +use phpMyFAQ\Session\Token; |
| 25 | +use phpMyFAQ\System; |
| 26 | +use phpMyFAQ\Translation; |
| 27 | +use Symfony\Component\HttpFoundation\Request; |
| 28 | +use Symfony\Component\HttpFoundation\Response; |
| 29 | +use Symfony\Component\Routing\Attribute\Route; |
| 30 | +use Twig\Error\LoaderError; |
| 31 | + |
| 32 | +class SessionKeepAliveController extends AbstractAdministrationController |
| 33 | +{ |
| 34 | + /** |
| 35 | + * @throws Exception |
| 36 | + * @throws LoaderError |
| 37 | + * @throws \Exception |
| 38 | + */ |
| 39 | + #[Route('/session-keep-alive', name: 'admin.session.keepalive', methods: ['GET'])] |
| 40 | + public function index(Request $request): Response |
| 41 | + { |
| 42 | + $language = Filter::filterVar($request->query->get('lang', 'en'), FILTER_SANITIZE_SPECIAL_CHARS); |
| 43 | + $refreshTime = (PMF_AUTH_TIMEOUT - PMF_AUTH_TIMEOUT_WARNING) * 60; |
| 44 | + |
| 45 | + return $this->render( |
| 46 | + '@admin/session-keepalive.twig', |
| 47 | + [ |
| 48 | + 'metaLanguage' => $language, |
| 49 | + 'phpMyFAQVersion' => System::getVersion(), |
| 50 | + 'currentYear' => date('Y'), |
| 51 | + 'isUserLoggedIn' => $this->currentUser->isLoggedIn(), |
| 52 | + 'csrfToken' => Token::getInstance($this->container->get('session'))->getTokenString('admin-logout'), |
| 53 | + 'msgConfirm' => sprintf(Translation::get('ad_session_expiring'), PMF_AUTH_TIMEOUT_WARNING), |
| 54 | + 'sessionTimeout' => PMF_AUTH_TIMEOUT, |
| 55 | + 'refreshTime' => $refreshTime, |
| 56 | + ] |
| 57 | + ); |
| 58 | + } |
| 59 | +} |
0 commit comments