aboutsummaryrefslogtreecommitdiff
path: root/cli/create-user.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2016-10-25 00:37:34 +0200
committerGravatar GitHub <noreply@github.com> 2016-10-25 00:37:34 +0200
commit062c65d22878f2402e4add7c1758d794d46aff48 (patch)
tree99047b1a45f706d3c21bde799c6d2a59ebd18b30 /cli/create-user.php
parent4d6fdc589e89c2a7d4072b497d9dfd8504a1cb5c (diff)
parent2cbf307963c72c4f5cf18732bb581a88a46d668b (diff)
Merge pull request #1338 from Alkarex/cli
CLI: Command-Line Interface
Diffstat (limited to 'cli/create-user.php')
-rwxr-xr-xcli/create-user.php48
1 files changed, 48 insertions, 0 deletions
diff --git a/cli/create-user.php b/cli/create-user.php
new file mode 100755
index 000000000..008b82ce3
--- /dev/null
+++ b/cli/create-user.php
@@ -0,0 +1,48 @@
+#!/usr/bin/php
+<?php
+require('_cli.php');
+
+$options = getopt('', array(
+ 'user:',
+ 'password:',
+ 'api-password:',
+ 'language:',
+ 'email:',
+ 'token:',
+ 'no-default-feeds',
+ ));
+
+if (empty($options['user'])) {
+ fail('Usage: ' . basename(__FILE__) . " --user username ( --password 'password' --api-password 'api_password'" .
+ " --language en --email user@example.net --token 'longRandomString --no-default-feeds' )");
+}
+$username = $options['user'];
+if (!ctype_alnum($username)) {
+ fail('FreshRSS error: invalid username “' . $username . '”');
+}
+
+$usernames = listUsers();
+if (preg_grep("/^$username$/i", $usernames)) {
+ fail('FreshRSS error: username already taken “' . $username . '”');
+}
+
+echo 'FreshRSS creating user “', $username, "”…\n";
+
+$ok = FreshRSS_user_Controller::createUser($username,
+ empty($options['password']) ? '' : $options['password'],
+ empty($options['api-password']) ? '' : $options['api-password'],
+ array(
+ 'language' => empty($options['language']) ? '' : $options['language'],
+ 'token' => empty($options['token']) ? '' : $options['token'],
+ ),
+ !isset($options['no-default-feeds']));
+
+if (!$ok) {
+ fail('FreshRSS could not create user!');
+}
+
+invalidateHttpCache(FreshRSS_Context::$system_conf->default_user);
+
+accessRights();
+
+done($ok);