/**
  * Saves a Placid_OAuthModel and also the Oauth_TokenModel which is handy
  * @param  String           $provider Name of the provider we want to save
  * @param  Oauth_TokenModel $token    The OAuth token model we want to save
  * @return Bool                       1 or 0 if successfull
  */
 public function saveToken($provider, Oauth_TokenModel $token)
 {
     $tokenModel = $this->findByHandle($provider);
     $existingToken = null;
     if ($tokenModel) {
         $existingToken = craft()->oauth->getTokenById($tokenModel->tokenId);
         $record = $this->record->findByPk($tokenModel->id);
     } else {
         $record = new Placid_OAuthRecord();
     }
     if ($existingToken) {
         $token->id = $existingToken->id;
     }
     // save token
     craft()->oauth->saveToken($token);
     $attributes = array('tokenId' => $token->id, 'handle' => $provider);
     // Set the new attributes to the record
     $record->setAttributes($attributes, false);
     return $record->save();
 }
Esempio n. 2
0
 /**
  * Deletes a token from both Placid and the OAuth plugin
  * @param  String $provider Name of the provider's token we want to delete
  * @return Bool           true if delete was successful
  */
 public function deleteToken($provider)
 {
     $tokenModel = $this->findByHandle($provider);
     $oauthTokenModel = craft()->oauth->getTokenById($tokenModel->id);
     craft()->oauth->deleteToken($oauthTokenModel);
     if ($tokenModel) {
         Placid_OAuthRecord::model()->deleteByPk($tokenModel->id);
     }
     return true;
 }