2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)2002-2007 Blue Static
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.
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
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 \*=====================================================================*/
22 $fetchtemplates = array(
27 $focus['user'] = 'focus';
29 require_once('./global.php');
30 require_once('./includes/api_user.php');
32 require_once('./includes/class_api_error.php');
33 APIError(array(new API_Error_Handler($message), 'user_cumulative'));
35 // ###################################################################
37 if ($_POST['do'] == 'insert')
39 if ($bugsys->userinfo
['userid'])
41 $message->error(T('Sorry, you are already registered.'));
44 if (!$bugsys->options
['allownewreg'])
46 $message->error(T('Sorry, we don\'t allow new registrations.'));
49 if ($bugsys->in
['email'] != $bugsys->in
['confirmemail'])
51 $message->addError(T('The emails you entered do not match.'));
54 if ($bugsys->in
['password'] != $bugsys->in
['confirmpassword'])
56 $message->addError(T('The passwords you entered did not match.'));
59 if ($bugsys->options
['recaptchasitekey'] && $bugsys->options
['recaptchasecretkey'])
61 if ($bugsys->in
['g-recaptcha-response'])
63 $request = http_build_query([
64 'secret' => $bugsys->options
['recaptchasecretkey'],
65 'response' => $bugsys->in
['g-recaptcha-response'],
66 'remoteip' => $_SERVER['REMOTE_ADDR'],
68 $context = stream_context_create([
71 'header' => 'Content-type: application/x-www-form-urlencoded',
72 'content' => $request,
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
)
79 $message->addError(T('Sorry, you do not appear to be human.'));
84 $message->addError(T('Please verify you are a human.'));
88 if ($bugsys->options
['verifyemail'])
94 if ($bugsys->options
['moderatenewusers'])
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);
114 if (!$message->hasErrors())
118 $userid = $user->insertid
;
120 // Verify email address
121 if ($usergroupid == 3)
123 $activationid = $funct->rand(25);
125 $db->query("INSERT INTO " . TABLE_PREFIX
. "useractivation (userid, activator, dateline, usergroupid) VALUES ($userid, '$activationid', " . TIMENOW
. ", 2)");
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']);
132 $mail->send($bugsys->in
['email'], $bugsys->in
['displayname']);
134 $message->message(T('You now need to activate your account via email.'));
136 else if ($usergroupid == 4 OR $usergroupid == 2)
138 if ($bugsys->options
['sendwelcomemail'])
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']);
148 if ($usergroupid == 4)
150 $message->message(T('Your account is pending approval.'));
154 $message->message(T('Thank you for registering. You may now use your account.'));
160 $_REQUEST['do'] = '';
161 $show['errors'] = true
;
165 // ###################################################################
167 if (empty($_REQUEST['do']))
169 if ($bugsys->userinfo
['userid'])
171 $message->error(T('Sorry, you are already registered.'));
174 if (!$bugsys->options
['allownewreg'])
176 $message->error(T('Sorry, we don\'t allow new registrations.'));
179 foreach (bugdar
::$datastore['language'] AS $value => $temp)
181 $label = $temp['title'];
182 $selected = ($value == $bugsys->in
['languageid']);
183 eval('$opts .= "' . $template->fetch('selectoption') . '";');
186 eval('$template->flush("' . $template->fetch('register') . '");');
189 // ###################################################################
191 if ($_REQUEST['do'] == 'activate')
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') . "'"))
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']);
200 if ($bugsys->options
['sendwelcomemail'])
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']);
210 $message->message(T('Your account is now activated and you can now login.'));
214 $message->error(T('Sorry, we could not match your registration string. Please make sure you entered the correct URL.'));