mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-01-24 21:27:56 -05:00
* Updates do-install params * Adds parseCliParams to _cli.php * Updates do-install to use parseCliParams * Updates reconfigure to use parseCliParams * Fixes bug mail_login => email * Update create-user to use parseCliParams * Minor refactor * Updates update-user to use parseCliParams * Fix no_default_feeds => no-default-feeds * Refactors arrays * Updates CLI Readme * Adds docblocks to _cli functions * Sets vars in _cli functions * Fixes indentation * Meeting coding standards around colons * Meeting PHPStan standards * Removes stray whitespace * Meeting PHPStan Next Level standards * More specific typing * Maintaining types * Typing around getopt() * Fixes typo * Fixes typo perameters -> parameters * Removes unused variable * Rewrites deprecation warning message
49 lines
1.3 KiB
PHP
Executable File
49 lines
1.3 KiB
PHP
Executable File
#!/usr/bin/env php
|
||
<?php
|
||
declare(strict_types=1);
|
||
|
||
$isUpdate = false;
|
||
require(__DIR__ . '/_update-or-create-user.php');
|
||
|
||
$username = $GLOBALS['options']['valid']['user'];
|
||
if (!FreshRSS_user_Controller::checkUsername($username)) {
|
||
fail('FreshRSS error: invalid username “' . $username .
|
||
'”! Must be matching ' . FreshRSS_user_Controller::USERNAME_PATTERN);
|
||
}
|
||
|
||
$usernames = listUsers();
|
||
if (preg_grep("/^$username$/i", $usernames)) {
|
||
fail('FreshRSS warning: username already exists “' . $username . '”', EXIT_CODE_ALREADY_EXISTS);
|
||
}
|
||
|
||
echo 'FreshRSS creating user “', $username, "”…\n";
|
||
|
||
$ok = FreshRSS_user_Controller::createUser(
|
||
$username,
|
||
empty($options['valid']['email']) ? '' : $options['valid']['email'],
|
||
empty($options['valid']['password']) ? '' : $options['valid']['password'],
|
||
$GLOBALS['values'],
|
||
!isset($options['valid']['no-default-feeds'])
|
||
);
|
||
|
||
if (!$ok) {
|
||
fail('FreshRSS could not create user!');
|
||
}
|
||
|
||
if (!empty($options['valid']['api-password'])) {
|
||
$username = cliInitUser($username);
|
||
$error = FreshRSS_api_Controller::updatePassword($options['valid']['api-password']);
|
||
if ($error !== false) {
|
||
fail($error);
|
||
}
|
||
}
|
||
|
||
invalidateHttpCache(FreshRSS_Context::systemConf()->default_user);
|
||
|
||
echo 'ℹ️ Remember to refresh the feeds of the user: ', $username ,
|
||
"\t", './cli/actualize-user.php --user ', $username, "\n";
|
||
|
||
accessRights();
|
||
|
||
done($ok);
|