User_username.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. defined('GNUSOCIAL') || die();
  17. require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
  18. /**
  19. * Table Definition for user_username
  20. */
  21. class User_username extends Managed_DataObject
  22. {
  23. ###START_AUTOCODE
  24. /* the code below is auto generated do not remove the above tag */
  25. public $__table = 'user_username'; // table name
  26. public $user_id; // int(4) not_null
  27. public $provider_name; // varchar(191) primary_key not_null not 255 because utf8mb4 takes more space
  28. public $username; // varchar(191) primary_key not_null not 255 because utf8mb4 takes more space
  29. public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
  30. public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
  31. /* the code above is auto generated do not remove the tag below */
  32. ###END_AUTOCODE
  33. public static function schemaDef()
  34. {
  35. return array(
  36. 'fields' => array(
  37. 'provider_name' => array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'provider name'),
  38. 'username' => array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'username'),
  39. 'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice id this title relates to'),
  40. 'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
  41. 'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),
  42. ),
  43. 'primary key' => array('provider_name', 'username'),
  44. 'indexes' => array(
  45. 'user_id_idx' => array('user_id')
  46. ),
  47. 'foreign keys' => array(
  48. 'user_username_user_id_fkey' => array('user', array('user_id' => 'id')),
  49. ),
  50. );
  51. }
  52. /**
  53. * Register a user with a username on a given provider
  54. * @param User User object
  55. * @param string username on the given provider
  56. * @param provider_name string name of the provider
  57. * @return mixed User_username instance if the registration succeeded, false if it did not
  58. */
  59. public static function register($user, $username, $provider_name)
  60. {
  61. $user_username = new User_username();
  62. $user_username->user_id = $user->id;
  63. $user_username->provider_name = $provider_name;
  64. $user_username->username = $username;
  65. $user_username->created = common_sql_now();
  66. if ($user_username->insert()) {
  67. return $user_username;
  68. } else {
  69. return false;
  70. }
  71. }
  72. }