]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/RequireValidatedEmail/registerbyemail.php
Localisation updates from http://translatewiki.net.
[quix0rs-gnu-social.git] / plugins / RequireValidatedEmail / registerbyemail.php
1 #!/usr/bin/env php
2 <?php
3 /*
4  * StatusNet - the distributed open-source microblogging tool
5  * Copyright (C) 2009, StatusNet, Inc.
6  *
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.
11  *
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.
16  *
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/>.
19  */
20
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
22
23 $shortoptions = "e:";
24
25 $helptext = <<<END_OF_REGISTERBYEMAIL_HELP
26 USAGE: registerbyemail.php
27 Registers a new user by email address and sends a confirmation email
28
29   -e email     Email to register
30
31 END_OF_REGISTERBYEMAIL_HELP;
32
33 require_once INSTALLDIR.'/scripts/commandline.inc';
34
35 $email = get_option_value('e', 'email');
36
37 $parts = explode('@', $email);
38 $nickname = common_nicknamize($parts[0]);
39
40 $user = User::staticGet('nickname', $nickname);
41
42 if (!empty($user)) {
43     $confirm = new Confirm_address();
44
45     $confirm->user_id      = $user->id;
46     $confirm->address_type = 'email';
47
48     if ($confirm->find(true)) {
49         $url = common_local_url('confirmfirstemail',
50                                 array('code' => $confirm->code));
51
52         print "$url\n";
53     } else {
54         print "User not waiting for confirmation.\n";
55     }
56
57     exit;
58 }
59
60 $user = User::register(array('nickname' => $nickname,
61                              'password' => null));
62
63 $confirm = new Confirm_address();
64 $confirm->code = common_confirmation_code(128);
65 $confirm->user_id = $user->id;
66 $confirm->address = $email;
67 $confirm->address_type = 'email';
68
69 $confirm->insert();
70
71 $url = common_local_url('confirmfirstemail',
72                         array('code' => $confirm->code));
73
74 print "$url\n";
75
76 mail_confirm_address($user,
77                      $confirm->code,
78                      $user->nickname,
79                      $email,
80                      $url);