A free, self-hostable news aggregator…
CLI update user
Alexandre Alapetitee046791c9330
diff --git a/app/Controllers/userController.php b/app/Controllers/userController.phpindex 3cbbd8633..a58501186 100644--- a/app/Controllers/userController.php+++ b/app/Controllers/userController.php@@ -44,6 +44,29 @@ class FreshRSS_user_Controller extends Minz_ActionController {return preg_match('/^' . self::USERNAME_PATTERN . '$/', $username) === 1;}+ public static function updateContextUser($passwordPlain, $apiPasswordPlain, $userConfigUpdated = array()) {+ if ($passwordPlain != '') {+ $passwordHash = self::hashPassword($passwordPlain);+ FreshRSS_Context::$user_conf->passwordHash = $passwordHash;+ }++ if ($apiPasswordPlain != '') {+ $apiPasswordHash = self::hashPassword($apiPasswordPlain);+ FreshRSS_Context::$user_conf->apiPasswordHash = $apiPasswordHash;+ }++ if (is_array($userConfigUpdated)) {+ foreach ($userConfigUpdated as $configName => $configValue) {+ if ($configValue !== null) {+ FreshRSS_Context::$user_conf->_param($configName, $configValue);+ }+ }+ }++ $ok = FreshRSS_Context::$user_conf->save();+ return $ok;+ }+/*** This action displays the user profile page.*/@@ -55,30 +78,17 @@ class FreshRSS_user_Controller extends Minz_ActionController {));if (Minz_Request::isPost()) {- $ok = true;-$passwordPlain = Minz_Request::param('newPasswordPlain', '', true);- if ($passwordPlain != '') {- Minz_Request::_param('newPasswordPlain'); //Discard plain-text password ASAP- $_POST['newPasswordPlain'] = '';- $passwordHash = self::hashPassword($passwordPlain);- $ok &= ($passwordHash != '');- FreshRSS_Context::$user_conf->passwordHash = $passwordHash;- }- Minz_Session::_param('passwordHash', FreshRSS_Context::$user_conf->passwordHash);+ Minz_Request::_param('newPasswordPlain'); //Discard plain-text password ASAP+ $_POST['newPasswordPlain'] = '';- $passwordPlain = Minz_Request::param('apiPasswordPlain', '', true);- if ($passwordPlain != '') {- $passwordHash = self::hashPassword($passwordPlain);- $ok &= ($passwordHash != '');- FreshRSS_Context::$user_conf->apiPasswordHash = $passwordHash;- }+ $apiPasswordPlain = Minz_Request::param('apiPasswordPlain', '', true);- $current_token = FreshRSS_Context::$user_conf->token;- $token = Minz_Request::param('token', $current_token);- FreshRSS_Context::$user_conf->token = $token;+ $ok = self::updateContextUser($passwordPlain, $apiPasswordPlain, array(+ 'token' => Minz_Request::param('token', null),+ ));- $ok &= FreshRSS_Context::$user_conf->save();+ Minz_Session::_param('passwordHash', FreshRSS_Context::$user_conf->passwordHash);if ($ok) {Minz_Request::good(_t('feedback.profile.updated'),diff --git a/cli/README.md b/cli/README.mdindex 1ac8c95ce..6e120babe 100644--- a/cli/README.md+++ b/cli/README.md@@ -46,6 +46,8 @@ cd /usr/share/FreshRSS./cli/create-user.php --user username ( --password 'password' --api-password 'api_password' --language en --email [email protected] --token 'longRandomString' --no-default-feeds )# --language can be: 'en' (default), 'fr', or one of the [supported languages](../app/i18n/)+./cli/update-user.php --user username ( --password 'password' --api-password 'api_password' --language en --email [email protected] --token 'longRandomString' --purge_after_months 3 --feed_min_articles_default 50 --feed_ttl_default 3600 --since_hours_posts_per_rss 168 --min_posts_per_rss 2 --max_posts_per_rss 400 )+./cli/delete-user.php --user username./cli/list-users.phpdiff --git a/cli/create-user.php b/cli/create-user.phpindex c9e350c14..0b131ac35 100755--- a/cli/create-user.php+++ b/cli/create-user.php@@ -33,6 +33,7 @@ $ok = FreshRSS_user_Controller::createUser($username,empty($options['api-password']) ? '' : $options['api-password'],array('language' => empty($options['language']) ? '' : $options['language'],+ 'mail_login' => empty($options['email']) ? '' : $options['email'],'token' => empty($options['token']) ? '' : $options['token'],),!isset($options['no-default-feeds']));diff --git a/cli/update-user.php b/cli/update-user.phpnew file mode 100644index 000000000..5f3335f2e--- /dev/null+++ b/cli/update-user.php@@ -0,0 +1,54 @@+#!/usr/bin/php+<?php+require('_cli.php');++$options = getopt('', array(+ 'user:',+ 'password:',+ 'api-password:',+ 'language:',+ 'email:',+ 'token:',+ 'purge_after_months:',+ 'feed_min_articles_default:',+ 'feed_ttl_default:',+ 'since_hours_posts_per_rss:',+ 'min_posts_per_rss:',+ 'max_posts_per_rss:',+ ));++if (empty($options['user'])) {+ fail('Usage: ' . basename(__FILE__) . " --user username ( --password 'password' --api-password 'api_password'" .+ " --language en --email [email protected] --token 'longRandomString' )");+}++$username = cliInitUser($options['user']);++echo 'FreshRSS updating user “', $username, "”…\n";++function intParam($name) {+ return isset($options[$name]) && ctype_digit($options[$name]) ? intval($options[$name]) : null;+}++$ok = FreshRSS_user_Controller::updateContextUser($username,+ empty($options['password']) ? '' : $options['password'],+ empty($options['api-password']) ? '' : $options['api-password'],+ array(+ 'language' => isset($options['language']) ? $options['language'] : null,+ 'mail_login' => isset($options['email']) ? $options['email'] : null,+ 'token' => isset($options['token']) ? $options['token'] : null,+ 'old_entries' => intParam('purge_after_months'),+ 'keep_history_default' => intParam('feed_min_articles_default'),+ 'ttl_default' => intParam('feed_ttl_default'),+ 'since_hours_posts_per_rss' => intParam('since_hours_posts_per_rss'),+ 'min_posts_per_rss' => intParam('min_posts_per_rss'),+ 'max_posts_per_rss' => intParam('max_posts_per_rss'),+ ));++if (!$ok) {+ fail('FreshRSS could not update user!');+}++invalidateHttpCache($username);++done($ok);