Esempio n. 1
0
 /**
  * {@inheritdoc}
  *
  * @param Request $request
  *
  * @return Response never null
  */
 public function logout(Request $request, Response $response, TokenInterface $token)
 {
     $this->userModel->setOnlineStatus('offline');
     if ($this->dispatcher->hasListeners(UserEvents::USER_LOGOUT)) {
         $event = new LogoutEvent($this->user, $request);
         $this->dispatcher->dispatch(UserEvents::USER_LOGOUT, $event);
     }
     // Clear session
     $session = $request->getSession();
     $session->clear();
     if (isset($event)) {
         $sessionItems = $event->getPostSessionItems();
         foreach ($sessionItems as $key => $value) {
             $session->set($key, $value);
         }
     }
     // Note that a logout occurred
     $session->set('post_logout', true);
 }
Esempio n. 2
0
 /**
  * Set vars on login.
  *
  * @param InteractiveLoginEvent $event
  */
 public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
 {
     if (defined('MAUTIC_INSTALLER')) {
         return;
     }
     $session = $event->getRequest()->getSession();
     if ($this->securityContext->isGranted('IS_AUTHENTICATED_FULLY') || $this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         $user = $event->getAuthenticationToken()->getUser();
         //set a session var for filemanager to know someone is logged in
         $session->set('mautic.user', $user->getId());
         //mark the user as last logged in
         $user = $this->userHelper->getUser();
         if ($user instanceof User) {
             $this->userModel->setOnlineStatus('online');
             $this->userModel->getRepository()->setLastLogin($user);
             // Set the timezone and locale in session while we have it since Symfony dispatches the onKernelRequest prior to the
             // firewall setting the known user
             $tz = $user->getTimezone();
             if (empty($tz)) {
                 $tz = $this->params['default_timezone'];
             }
             $session->set('_timezone', $tz);
             $locale = $user->getLocale();
             if (empty($locale)) {
                 $locale = $this->params['locale'];
             }
             $session->set('_locale', $locale);
         }
         //dispatch on login events
         if ($this->dispatcher->hasListeners(UserEvents::USER_LOGIN)) {
             $event = new LoginEvent($this->userHelper->getUser());
             $this->dispatcher->dispatch(UserEvents::USER_LOGIN, $event);
         }
     } else {
         $session->remove('mautic.user');
     }
     //set a couple variables used by filemanager
     $session->set('mautic.docroot', $event->getRequest()->server->get('DOCUMENT_ROOT'));
     $session->set('mautic.basepath', $event->getRequest()->getBasePath());
     $session->set('mautic.imagepath', $this->coreParametersHelper->getParameter('image_path'));
 }