aboutsummaryrefslogtreecommitdiff
path: root/cli/create-user.php
blob: f94a0aa7a349b30f8e9d6bc0651fb1612619d79a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env php
<?php
$isUpdate = false;
require(__DIR__ . '/_update-or-create-user.php');

$username = $options['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['mail_login']) ? '' : $options['mail_login'],
	empty($options['password']) ? '' : $options['password'],
	$values,
	!isset($options['no_default_feeds'])
);

if (!$ok) {
	fail('FreshRSS could not create user!');
}

if (!empty($options['api_password'])) {
	$username = cliInitUser($username);
	$error = FreshRSS_api_Controller::updatePassword($options['api_password']);
	if ($error) {
		fail($error);
	}
}

invalidateHttpCache(FreshRSS_Context::$system_conf->default_user);

echo 'ℹ️ Remember to refresh the feeds of the user: ', $username ,
	"\t", './cli/actualize-user.php --user ', $username, "\n";

accessRights();

done($ok);