handles session timeouts in modals (#1092)

This commit is contained in:
Kevin Papst
2019-09-10 17:07:34 +02:00
committed by GitHub
parent a651e55dc9
commit cdcf9eaf67
12 changed files with 86 additions and 14 deletions

View File

@@ -0,0 +1,44 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\AuthenticationExpiredException;
class AjaxAuthenticationSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
KernelEvents::EXCEPTION => ['onCoreException', 1]
];
}
public function onCoreException(ExceptionEvent $event)
{
$request = $event->getRequest();
if ($request->isXmlHttpRequest()) {
$exception = $event->getException();
if ($exception instanceof AuthenticationExpiredException) {
$event->setResponse(new Response('Session expired', 403, ['Login-Required' => true]));
} elseif ($exception instanceof AuthenticationException) {
$event->setResponse(new Response('Authentication problem', 403, ['Login-Required' => true]));
} elseif ($exception instanceof AccessDeniedException) {
$event->setResponse(new Response('Access denied', 403, ['Login-Required' => true]));
}
}
}
}

View File

@@ -25,7 +25,7 @@ class TimesheetToolbarForm extends AbstractToolbarForm
{
$this->addSearchTermInputField($builder);
if ($options['include_user']) {
$this->addUserChoice($builder);
$this->addUsersChoice($builder);
}
$this->addDateRangeChoice($builder);
$this->addCustomerChoice($builder);