Fix DB_MySQL_PDO::escape_binary().
[bugdar.git] / register.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2002-2007 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 $fetchtemplates = array(
23 'register'
24 );
25
26
27 $focus['user'] = 'focus';
28
29 require_once('./global.php');
30 require_once('./includes/api_user.php');
31
32 require_once('./includes/class_api_error.php');
33 APIError(array(new API_Error_Handler($message), 'user_cumulative'));
34
35 // ###################################################################
36
37 if ($_POST['do'] == 'insert')
38 {
39 if ($bugsys->userinfo['userid'])
40 {
41 $message->error(T('Sorry, you are already registered.'));
42 }
43
44 if (!$bugsys->options['allownewreg'])
45 {
46 $message->error(T('Sorry, we don\'t allow new registrations.'));
47 }
48
49 if ($bugsys->in['email'] != $bugsys->in['confirmemail'])
50 {
51 $message->addError(T('The emails you entered do not match.'));
52 }
53
54 if ($bugsys->in['password'] != $bugsys->in['confirmpassword'])
55 {
56 $message->addError(T('The passwords you entered did not match.'));
57 }
58
59 if ($bugsys->options['recaptchasitekey'] && $bugsys->options['recaptchasecretkey'])
60 {
61 if ($bugsys->in['g-recaptcha-response'])
62 {
63 $request = http_build_query([
64 'secret' => $bugsys->options['recaptchasecretkey'],
65 'response' => $bugsys->in['g-recaptcha-response'],
66 'remoteip' => $_SERVER['REMOTE_ADDR'],
67 ]);
68 $context = stream_context_create([
69 'http' => [
70 'method' => 'POST',
71 'header' => 'Content-type: application/x-www-form-urlencoded',
72 'content' => $request,
73 ]
74 ]);
75 $response = @file_get_contents('https://www.google.com/recaptcha/api/siteverify', false, $context);
76 $response_object = json_decode($response);
77 if (!$response_object || !$response_object->success)
78 {
79 $message->addError(T('Sorry, you do not appear to be human.'));
80 }
81 }
82 else
83 {
84 $message->addError(T('Please verify you are a human.'));
85 }
86 }
87
88 if ($bugsys->options['verifyemail'])
89 {
90 $usergroupid = 3;
91 }
92 else
93 {
94 if ($bugsys->options['moderatenewusers'])
95 {
96 $usergroupid = 4;
97 }
98 else
99 {
100 $usergroupid = 2;
101 }
102 }
103
104 $user = new UserAPI($bugsys);
105 $user->set('email', $bugsys->in['email']);
106 $user->set('displayname', $bugsys->in['displayname']);
107 $user->set('password', $bugsys->in['password']);
108 $user->set('showemail', $bugsys->in['showemail']);
109 $user->set('showcolors', 1);
110 $user->set('languageid', $bugsys->in['languageid']);
111 $user->set('timezone', $bugsys->options['defaulttimezone']);
112 $user->set('usergroupid', $usergroupid);
113
114 if (!$message->hasErrors())
115 {
116 $user->insert();
117
118 $userid = $user->insertid;
119
120 // Verify email address
121 if ($usergroupid == 3)
122 {
123 $activationid = $funct->rand(25);
124
125 $db->query("INSERT INTO " . TABLE_PREFIX . "useractivation (userid, activator, dateline, usergroupid) VALUES ($userid, '$activationid', " . TIMENOW . ", 2)");
126
127 eval('$email = "' . $template->fetch(FetchEmailPath('activateaccount.xml', bugdar::$datastore['language'][$bugsys->in['languageid']]['langcode'])) . '";');
128 $email = $bugsys->xml->parse($email);
129 $mail->setSubject($email['email']['subject']['value']);
130 $mail->setBodyText($email['email']['bodyText']['value']);
131
132 $mail->send($bugsys->in['email'], $bugsys->in['displayname']);
133
134 $message->message(T('You now need to activate your account via email.'));
135 }
136 else if ($usergroupid == 4 OR $usergroupid == 2)
137 {
138 if ($bugsys->options['sendwelcomemail'])
139 {
140 $displayName = $bugsys->in['displayname'];
141 eval('$email = "' . $template->fetch(FetchEmailPath('welcome.xml', bugdar::$datastore['language'][$bugsys->in['languageid']]['langcode'])) . '";');
142 $email = $bugsys->xml->parse($email);
143 $mail->setSubject($email['email']['subject']['value']);
144 $mail->setBodyText($email['email']['bodyText']['value']);
145 $mail->send($bugsys->in['email'], $bugsys->in['displayname']);
146 }
147
148 if ($usergroupid == 4)
149 {
150 $message->message(T('Your account is pending approval.'));
151 }
152 else
153 {
154 $message->message(T('Thank you for registering. You may now use your account.'));
155 }
156 }
157 }
158 else
159 {
160 $_REQUEST['do'] = '';
161 $show['errors'] = true;
162 }
163 }
164
165 // ###################################################################
166
167 if (empty($_REQUEST['do']))
168 {
169 if ($bugsys->userinfo['userid'])
170 {
171 $message->error(T('Sorry, you are already registered.'));
172 }
173
174 if (!$bugsys->options['allownewreg'])
175 {
176 $message->error(T('Sorry, we don\'t allow new registrations.'));
177 }
178
179 foreach (bugdar::$datastore['language'] AS $value => $temp)
180 {
181 $label = $temp['title'];
182 $selected = ($value == $bugsys->in['languageid']);
183 eval('$opts .= "' . $template->fetch('selectoption') . '";');
184 }
185
186 eval('$template->flush("' . $template->fetch('register') . '");');
187 }
188
189 // ###################################################################
190
191 if ($_REQUEST['do'] == 'activate')
192 {
193 $bugsys->input_clean('userid', TYPE_UINT);
194 if ($useractivation = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "useractivation WHERE userid = " . $bugsys->in['userid'] . " AND activator = '" . $bugsys->input_escape('activator') . "'"))
195 {
196 $user = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = " . $bugsys->in['userid']);
197 $db->query("UPDATE " . TABLE_PREFIX . "user SET usergroupid = $useractivation[usergroupid] WHERE userid = " . $bugsys->in['userid']);
198 $db->query("DELETE FROM " . TABLE_PREFIX . "useractivation WHERE userid = " . $bugsys->in['userid']);
199
200 if ($bugsys->options['sendwelcomemail'])
201 {
202 $displayName = $user['displayname'];
203 eval('$email = "' . $template->fetch(FetchEmailPath('welcome.xml', bugdar::$datastore['language'][$user['languageid']]['langcode'])) . '";');
204 $email = $bugsys->xml->parse($email);
205 $mail->setSubject($email['email']['subject']['value']);
206 $mail->setBodyText($email['email']['bodyText']['value']);
207 $mail->send($user['email'], $user['displayname']);
208 }
209
210 $message->message(T('Your account is now activated and you can now login.'));
211 }
212 else
213 {
214 $message->error(T('Sorry, we could not match your registration string. Please make sure you entered the correct URL.'));
215 }
216 }
217