Пример #1
0
 /**
  * @param $criteria
  * @param int $lifetime (seconds)
  *
  * @return bool
  */
 public function Login($criteria, $lifetime)
 {
     $sid = (bool) $this->_sid;
     $storage = self::_storage($this->_name, $this->_sid);
     $this->_sid = Quark::GuID();
     $this->_signature = Quark::GuID();
     $this->_ttl = $lifetime;
     $old = $storage->Location();
     $storage->Location($storage->parent . '/' . $this->_name . '-' . $this->_sid . '.sid');
     $new = $storage->Location();
     if ($sid) {
         rename($old, $new);
     }
     $storage->Content(json_encode(array('user' => $this->_user->Extract(), 'signature' => $this->_signature, 'ttl' => $this->_ttl)));
     $storage->SaveContent();
     return $this->_end($lifetime);
 }
Пример #2
0
 /**
  * @param IQuarkModel $model
  * @param string $key
  *
  * @return QuarkModel|IQuarkModel
  */
 public function User(IQuarkModel $model, $key)
 {
     /**
      * @var QuarkModel|SocialNetwork $profile
      */
     $profile = QuarkModel::FindOne($this, array('social' => (string) $this->Name(), 'id' => (string) $this->id));
     if ($profile == null && $this->id != '' && $this->accessToken != '') {
         $profile = new QuarkModel($this);
         $profile->Create();
     }
     if ($profile == null) {
         return null;
     }
     $profile->accessToken = (string) $this->accessToken;
     $profile->Save();
     $user = QuarkModel::FindOne($model, array($key => $this->Pk()));
     if ($user == null) {
         $user = new QuarkModel($model, QuarkModel::StructureFromKey($key, $profile));
         $this->_newUser = true;
     }
     return $user;
 }