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', realpath(dirname(__FILE__) . '/..'));
23 $shortoptions = 'n:w:f:e:';
24 $longoptions = array('nickname=', 'password=', 'fullname=', 'email=');
26 $helptext = <<<END_OF_REGISTERUSER_HELP
27 registeruser.php [options]
28 registers a user in the database
30 -n --nickname nickname of the new user
31 -w --password password of the new user
32 -f --fullname full name of the new user (optional)
33 -e --email email address of the new user (optional)
35 END_OF_REGISTERUSER_HELP;
37 require_once INSTALLDIR.'/scripts/commandline.inc';
39 $nickname = get_option_value('n', 'nickname');
40 $password = get_option_value('w', 'password');
41 $fullname = get_option_value('f', 'fullname');
43 $email = get_option_value('e', 'email');
45 if (empty($nickname) || empty($password)) {
46 print "Must provide a username and password.\n";
52 $user = User::staticGet('nickname', $nickname);
55 throw new Exception("A user named '$nickname' already exists.");
58 $user = User::register(array('nickname' => $nickname,
59 'password' => $password,
60 'fullname' => $fullname));
63 throw new Exception("Can't register user '$nickname' with password '$password' and fullname '$fullname'.");
70 $user->email = $email;
72 if (!$user->updateKeys($orig)) {
74 throw new Exception("Can't update email address.");
78 } catch (Exception $e) {
79 print $e->getMessage() . "\n";