Example #1
0
 /**
  * Persist session data to storage.
  */
 public function persistData()
 {
     if ($this->authorisation === null) {
         return;
     }
     /** @var AccessToken $accessToken */
     foreach ($this->authorisation->getAccessTokens() as $provider => $accessToken) {
         $tokenEntities = $this->records->getTokensByGuid($this->authorisation->getGuid());
         if ($tokenEntities === false) {
             $tokenEntities[] = new Storage\Entity\Token();
         }
         /** @var Storage\Entity\Token $tokenEntity */
         foreach ($tokenEntities as $tokenEntity) {
             $tokenEntity->setGuid($this->authorisation->getGuid());
             $tokenEntity->setToken((string) $accessToken);
             $tokenEntity->setTokenType('access_token');
             $tokenEntity->setTokenData($accessToken);
             $tokenEntity->setExpires($accessToken->getExpires());
             $tokenEntity->setCookie($this->authorisation->getCookie());
             $this->records->saveToken($tokenEntity);
         }
     }
     $this->session->set(self::SESSION_AUTHORISATION, json_encode($this->authorisation));
 }
Example #2
0
 /**
  * Dispatch event to any listeners.
  *
  * @param string        $type          Either MembersEvents::MEMBER_LOGIN' or MembersEvents::MEMBER_LOGOUT
  * @param Authorisation $authorisation
  */
 protected function dispatchEvent($type, Authorisation $authorisation)
 {
     if (!$this->dispatcher->hasListeners($type)) {
         return;
     }
     $event = new MembersLoginEvent();
     $event->setAccount($authorisation->getAccount());
     try {
         $this->dispatcher->dispatch($type, $event);
     } catch (\Exception $e) {
         if ($this->config->isDebug()) {
             dump($e);
         }
         $this->logger->critical('Members event dispatcher had an error', ['event' => 'exception', 'exception' => $e]);
     }
 }