Esempio n. 1
0
 protected function deriveApiName($parameters)
 {
     $api_id = $parameters['api_id'];
     $api = ApiKeyTable::getInstance()->find($api_id);
     if (!$api) {
         throw new sfException('Cannot find ApiKey identified by ' . $api_id);
     }
     return $api->getApiAppName();
 }
 public function setPublicKeyIfNotSet()
 {
     if ($this->getApiKey()) {
         return;
     }
     $hash = '';
     do {
         $hash = md5(rand(0, 10) . microtime());
     } while (ApiKeyTable::getInstance()->findOneBy('api_key', $hash));
     $this->setApiKey($hash);
 }
 public function requestAuthKey($email_address, $password, $expires_in = null)
 {
     if (is_null($expires_in)) {
         $expires_in = sfConfig::get('app_web_app_api_auth_key_login_expiration');
     }
     if (!self::apiIsAuthorized()) {
         throw new sfException('API is not authorized to produce auth keys.');
     }
     $api = ApiKeyTable::getInstance()->findOneByApiKey($this->getAttribute('api_key'));
     if ($api->getApiKey() != sfConfig::get('app_web_app_api_key')) {
         $this->sendAuthRequestEmail($api);
     }
     return $api->requestAuthKey($email_address, $password, $expires_in);
 }
 /**
  * Signs out the user.
  *
  */
 public function signOut()
 {
     $auth_key = $this->getApiAuthKey();
     $this->getAttributeHolder()->removeNamespace('sfGuardSecurityUser');
     $this->user = null;
     $this->_user_id = null;
     $this->clearCredentials();
     $this->setAuthenticated(false);
     $api_key = sfConfig::get('app_web_app_api_key');
     $api = ApiKeyTable::getInstance()->findOneBy('api_key', $api_key);
     $auth_key = sfGuardUserAuthKeyTable::getInstance()->getMostRecentValidByApiKeyIdAndAuthKey($api->getIncremented(), $auth_key);
     if ($auth_key) {
         $auth_key->delete();
     }
     $expiration_age = sfConfig::get('app_sf_guard_plugin_remember_key_expiration_age', 15 * 24 * 3600);
     $remember_cookie = sfConfig::get('app_sf_guard_plugin_remember_cookie_name', 'sfRemember');
     sfContext::getInstance()->getResponse()->setCookie($remember_cookie, '', time() - $expiration_age);
 }