Oauth_token_association.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Table Definition for oauth_association
  4. */
  5. require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
  6. class Oauth_token_association extends Managed_DataObject
  7. {
  8. ###START_AUTOCODE
  9. /* the code below is auto generated do not remove the above tag */
  10. public $__table = 'oauth_token_association'; // table name
  11. public $profile_id; // int(4) primary_key not_null
  12. public $application_id; // int(4) primary_key not_null
  13. public $token; // varchar(191) primary key not null not 255 because utf8mb4 takes more space
  14. public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
  15. public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
  16. /* the code above is auto generated do not remove the tag below */
  17. ###END_AUTOCODE
  18. static function getByUserAndToken($user, $token)
  19. {
  20. if (empty($user) || empty($token)) {
  21. return null;
  22. }
  23. $oau = new oauth_request_token();
  24. $oau->profile_id = $user->id;
  25. $oau->token = $token;
  26. $oau->limit(1);
  27. $result = $oau->find(true);
  28. return empty($result) ? null : $oau;
  29. }
  30. public static function schemaDef()
  31. {
  32. return array(
  33. 'description' => 'Associate an application ID and profile ID with an OAuth token',
  34. 'fields' => array(
  35. 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'associated user'),
  36. 'application_id' => array('type' => 'int', 'not null' => true, 'description' => 'the application'),
  37. 'token' => array('type' => 'varchar', 'length' => '191', 'not null' => true, 'description' => 'token used for this association'),
  38. 'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
  39. 'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),
  40. ),
  41. 'primary key' => array('profile_id', 'application_id', 'token'),
  42. 'foreign keys' => array(
  43. 'oauth_token_association_profile_fkey' => array('profile_id', array('profile' => 'id')),
  44. 'oauth_token_association_application_fkey' => array('application_id', array('application' => 'id')),
  45. )
  46. );
  47. }
  48. }