Пример #1
0
 protected function checkIdentityAction()
 {
     if ($this->storage->isAuthenticated()) {
         $identity = $this->storage->getIdentity();
         $action = $this->identityHash->getHashAction(is_null($identity) ? $identity : $identity->hash);
         if (is_null($action)) {
             parent::logout();
         }
         switch ($action) {
             case IdentityHash::ACTION_RELOAD:
                 try {
                     $this->login($this->getId(), NULL);
                 } catch (Trejjam\Authorization\User\ManagerException $e) {
                     $this->logout();
                 } catch (Trejjam\Authorization\User\AuthenticatorException $e) {
                     //this may not happen
                     throw $e;
                 }
                 break;
             case IdentityHash::ACTION_LOGOUT:
                 $this->logout();
                 break;
             case IdentityHash::ACTION_DESTROYED:
                 $this->logout();
                 break;
         }
     }
 }
Пример #2
0
 /**
  * Sets the user identity.
  * @param Nette\Security\IIdentity $identity
  * @return Storage
  */
 public function setIdentity(Nette\Security\IIdentity $identity = NULL)
 {
     if (!is_null($identity)) {
         $identity->browser = $this->browser->getName();
         $identity->browserVersion = $this->browser->getVersion();
         $identity->hash = $this->identityHash->createIdentityHash($identity->getId(), $this->request->getRemoteAddress());
     }
     return parent::setIdentity($identity);
 }
Пример #3
0
 /**
  * @param        $username
  * @param bool   $all
  * @param string $type [username|id]
  * @return array
  */
 public function getIdentityHash($username, $all = FALSE, $type = 'username')
 {
     $user = $this->getUser($username, $type);
     $out = [];
     foreach ($this->identityHash->getUserHashes($user, $all ? [IdentityHash::ACTION_NONE, IdentityHash::ACTION_RELOAD, IdentityHash::ACTION_DESTROYED, IdentityHash::ACTION_LOGOUT] : [IdentityHash::ACTION_NONE, IdentityHash::ACTION_RELOAD]) as $v) {
         $out[$v->hash] = $v->ip;
     }
     return $out;
 }