create-user.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env php
  2. <?php
  3. declare(strict_types=1);
  4. $isUpdate = false;
  5. require(__DIR__ . '/_update-or-create-user.php');
  6. $username = $GLOBALS['options']['user'];
  7. if (!FreshRSS_user_Controller::checkUsername($username)) {
  8. fail('FreshRSS error: invalid username “' . $username .
  9. '”! Must be matching ' . FreshRSS_user_Controller::USERNAME_PATTERN);
  10. }
  11. $usernames = listUsers();
  12. if (preg_grep("/^$username$/i", $usernames)) {
  13. fail('FreshRSS warning: username already exists “' . $username . '”', EXIT_CODE_ALREADY_EXISTS);
  14. }
  15. echo 'FreshRSS creating user “', $username, "”…\n";
  16. $ok = FreshRSS_user_Controller::createUser(
  17. $username,
  18. empty($options['mail_login']) ? '' : $options['mail_login'],
  19. empty($options['password']) ? '' : $options['password'],
  20. $GLOBALS['values'],
  21. !isset($options['no_default_feeds'])
  22. );
  23. if (!$ok) {
  24. fail('FreshRSS could not create user!');
  25. }
  26. if (!empty($options['api_password'])) {
  27. $username = cliInitUser($username);
  28. $error = FreshRSS_api_Controller::updatePassword($options['api_password']);
  29. if ($error !== false) {
  30. fail($error);
  31. }
  32. }
  33. invalidateHttpCache(FreshRSS_Context::systemConf()->default_user);
  34. echo 'ℹ️ Remember to refresh the feeds of the user: ', $username ,
  35. "\t", './cli/actualize-user.php --user ', $username, "\n";
  36. accessRights();
  37. done($ok);