create-user.php 1.3 KB

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