src/Admin/Service/ScreenLockerService.php line 43

  1. <?php
  2. namespace App\Admin\Service;
  3. use Symfony\Component\HttpFoundation\RequestStack;
  4. use Symfony\Component\HttpFoundation\RedirectResponse;
  5. use App\Admin\Modules\User\Service\UserService;
  6. class ScreenLockerService
  7. {
  8.     private $_requestStack;
  9.     private $_userService;
  10.     private $_sessionKey 'admin.screen_locker.locked';
  11.     
  12.     public function __construct(
  13.             RequestStack $requestStack,
  14.             UserService $userService)
  15.     {
  16.         $this->_requestStack $requestStack;
  17.         $this->_userService $userService;
  18.     }
  19.     
  20.     public function lock()
  21.     {
  22.         $this->_requestStack->getMainRequest()->getSession()->set($this->_sessionKeytrue);
  23.     }
  24.     
  25.     public function unlock($pin)
  26.     {
  27.         if ($pin != $this->_userService->getLoggedUser()->getScreenLockerPin())
  28.             return false;
  29.         
  30.         $this->_requestStack->getMainRequest()->getSession()->set($this->_sessionKeyfalse);
  31.         
  32.         return true;
  33.     }
  34.     
  35.     public function checkLock()
  36.     {
  37.         $request $this->_requestStack->getMainRequest();
  38.         
  39.         if ($request->isXmlHttpRequest() ||
  40.                 !$request->getSession()->get($this->_sessionKey) ||
  41.                 $request->get('_route') == 'admin_screen_locker_unlock_ajax' || 
  42.                 !$this->_userService->getLoggedUser())
  43.             return;
  44.         $this->_userService->logout();
  45.         
  46.         $response = new RedirectResponse($request->getRequestUri());
  47.         $response->send();
  48.         
  49.         exit();
  50.     }
  51. }