123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- defined('GNUSOCIAL') || die();
- class Consumer extends Managed_DataObject
- {
-
-
- public $__table = 'consumer';
- public $consumer_key;
- public $consumer_secret;
- public $seed;
- public $created;
- public $modified;
-
-
- public static function schemaDef()
- {
- return array(
- 'description' => 'OAuth consumer record',
- 'fields' => array(
- 'consumer_key' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'unique identifier, root URL'),
- 'consumer_secret' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'secret value'),
- 'seed' => array('type' => 'char', 'length' => 32, 'not null' => true, 'description' => 'seed for new tokens by this consumer'),
- 'created' => array('type' => 'datetime', 'description' => 'date this record was created'),
- 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
- ),
- 'primary key' => array('consumer_key'),
- );
- }
- public static function generateNew()
- {
- $cons = new Consumer();
- $rand = common_random_hexstr(16);
- $cons->seed = $rand;
- $cons->consumer_key = md5(time() + $rand);
- $cons->consumer_secret = md5(md5(time() + time() + $rand));
- $cons->created = common_sql_now();
- return $cons;
- }
-
- public function delete($useWhere = false)
- {
-
- $this->deleteTokens();
- $this->deleteNonces();
- return parent::delete($useWhere);
- }
- private function deleteTokens()
- {
- $token = new Token();
- $token->consumer_key = $this->consumer_key;
- $token->delete();
- }
- private function deleteNonces()
- {
- $nonce = new Nonce();
- $nonce->consumer_key = $this->consumer_key;
- $nonce->delete();
- }
- }
|