Oauth_token_association.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Table Definition for oauth_association
  18. */
  19. defined('GNUSOCIAL') || die();
  20. class Oauth_token_association extends Managed_DataObject
  21. {
  22. ###START_AUTOCODE
  23. /* the code below is auto generated do not remove the above tag */
  24. public $__table = 'oauth_token_association'; // table name
  25. public $profile_id; // int(4) primary_key not_null
  26. public $application_id; // int(4) primary_key not_null
  27. public $token; // varchar(191) primary key not null not 255 because utf8mb4 takes more space
  28. public $created; // datetime()
  29. public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
  30. /* the code above is auto generated do not remove the tag below */
  31. ###END_AUTOCODE
  32. public static function getByUserAndToken($user, $token)
  33. {
  34. if (empty($user) || empty($token)) {
  35. return null;
  36. }
  37. $oau = new oauth_request_token();
  38. $oau->profile_id = $user->id;
  39. $oau->token = $token;
  40. $oau->limit(1);
  41. $result = $oau->find(true);
  42. return empty($result) ? null : $oau;
  43. }
  44. public static function schemaDef()
  45. {
  46. return array(
  47. 'description' => 'Associate an application ID and profile ID with an OAuth token',
  48. 'fields' => array(
  49. 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'associated user'),
  50. 'application_id' => array('type' => 'int', 'not null' => true, 'description' => 'the application'),
  51. 'token' => array('type' => 'varchar', 'length' => '191', 'not null' => true, 'description' => 'token used for this association'),
  52. 'created' => array('type' => 'datetime', 'description' => 'date this record was created'),
  53. 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
  54. ),
  55. 'primary key' => array('profile_id', 'application_id', 'token'),
  56. 'foreign keys' => array(
  57. 'oauth_token_association_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
  58. 'oauth_token_association_application_id_fkey' => array('oauth_application', array('application_id' => 'id')),
  59. ),
  60. 'indexes' => array(
  61. 'oauth_token_association_application_id_idx' => array('application_id'),
  62. ),
  63. );
  64. }
  65. }