4 * StatusNet - a distributed open-source microblogging tool
5 * Copyright (C) 2008, 2009, StatusNet, Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 define('INSTALLDIR', dirname(__DIR__));
22 define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
24 $shortoptions = 'n:w:f:e:';
25 $longoptions = array('nickname=', 'password=', 'fullname=', 'email=');
27 $helptext = <<<END_OF_REGISTERUSER_HELP
28 registeruser.php [options]
29 registers a user in the database
31 -n --nickname nickname of the new user
32 -w --password password of the new user
33 -f --fullname full name of the new user (optional)
34 -e --email email address of the new user (optional)
36 END_OF_REGISTERUSER_HELP;
38 require_once INSTALLDIR.'/scripts/commandline.inc';
40 $nickname = get_option_value('n', 'nickname');
41 $password = get_option_value('w', 'password');
42 $fullname = get_option_value('f', 'fullname');
44 $email = get_option_value('e', 'email');
46 if (empty($nickname) || empty($password)) {
47 print "Must provide a username and password.\n";
53 $user = User::getKV('nickname', $nickname);
56 throw new Exception("A user named '$nickname' already exists.");
59 $user = User::register(array('nickname' => $nickname,
60 'password' => $password,
61 'fullname' => $fullname));
64 throw new Exception("Can't register user '$nickname' with password '$password' and fullname '$fullname'.");
71 $user->email = $email;
73 // Throws exception on failure.
74 $user->updateWithKeys($orig);
77 } catch (Exception $e) {
78 print $e->getMessage() . "\n";