registerbyemail.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env php
  2. <?php
  3. // This file is part of GNU social - https://www.gnu.org/software/social
  4. //
  5. // GNU social is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // GNU social is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  17. /**
  18. * @package GNUsocial
  19. * @copyright 2009 StatusNet, Inc.
  20. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  21. */
  22. define('INSTALLDIR', dirname(__DIR__, 3));
  23. define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
  24. $shortoptions = "e:";
  25. $helptext = <<<END_OF_REGISTERBYEMAIL_HELP
  26. USAGE: registerbyemail.php
  27. Registers a new user by email address and sends a confirmation email
  28. -e email Email to register
  29. END_OF_REGISTERBYEMAIL_HELP;
  30. require_once INSTALLDIR.'/scripts/commandline.inc';
  31. $email = get_option_value('e', 'email');
  32. $parts = explode('@', $email);
  33. $nickname = common_nicknamize($parts[0]);
  34. $user = User::getKV('nickname', $nickname);
  35. if (!empty($user)) {
  36. $confirm = new Confirm_address();
  37. $confirm->user_id = $user->id;
  38. $confirm->address_type = 'email';
  39. if ($confirm->find(true)) {
  40. $url = common_local_url(
  41. 'confirmfirstemail',
  42. ['code' => $confirm->code]
  43. );
  44. print "$url\n";
  45. } else {
  46. print "User not waiting for confirmation.\n";
  47. }
  48. exit;
  49. }
  50. $user = User::register(array('nickname' => $nickname,
  51. 'password' => null));
  52. $confirm = new Confirm_address();
  53. $confirm->code = common_confirmation_code(128);
  54. $confirm->user_id = $user->id;
  55. $confirm->address = $email;
  56. $confirm->address_type = 'email';
  57. $confirm->insert();
  58. $url = common_local_url(
  59. 'confirmfirstemail',
  60. ['code' => $confirm->code]
  61. );
  62. print "$url\n";
  63. $confirm->sendConfirmation(['url'=>$url]);