r1232: We should probably be catching register.php errors
[bugdar.git] / register.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] 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 [#]gpl[#] 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 define('SVN', '$Id$');
27
28 $focus['user'] = 'focus';
29
30 require_once('./global.php');
31 require_once('./includes/api_user.php');
32
33 require_once('./includes/class_api_error.php');
34 APIError(array(new API_Error_Handler($message), 'user_cumulative'));
35
36 // ###################################################################
37
38 if ($_POST['do'] == 'insert')
39 {
40 if ($bugsys->userinfo['userid'])
41 {
42 $message->error(_('Sorry, you are already registered.'));
43 }
44
45 if (!$bugsys->options['allownewreg'])
46 {
47 $message->error(_('Sorry, we don\'t allow new registrations.'));
48 }
49
50 if ($bugsys->in['email'] != $bugsys->in['confirmemail'])
51 {
52 $message->add_error(_('The emails you entered do not match.'));
53 }
54
55 if ($bugsys->in['password'] != $bugsys->in['confirmpassword'])
56 {
57 $message->add_error(_('The passwords you entered did not match.'));
58 }
59
60 if ($bugsys->options['verifyemail'])
61 {
62 $usergroupid = 3;
63 }
64 else
65 {
66 if ($bugsys->options['moderatenewusers'])
67 {
68 $usergroupid = 4;
69 }
70 else
71 {
72 $usergroupid = 2;
73 }
74 }
75
76 $user = new UserAPI($bugsys);
77 $user->set('email', $bugsys->in['email']);
78 $user->set('displayname', $bugsys->in['displayname']);
79 $user->set('password', $bugsys->in['password']);
80 $user->set('showemail', $bugsys->in['showemail']);
81 $user->set('showcolors', 1);
82 $user->set('languageid', $bugsys->in['languageid']);
83 $user->set('usergroupid', $usergroupid);
84
85 if (!$message->items)
86 {
87 $user->insert();
88
89 $userid = $user->insertid;
90
91 // Verify email address
92 if ($usergroupid == 3)
93 {
94 $activationid = $funct->rand(25);
95
96 $db->query("INSERT INTO " . TABLE_PREFIX . "useractivation (userid, activator, dateline, usergroupid) VALUES ($userid, '$activationid', " . TIMENOW . ", 2)");
97
98 $mail->to_add($bugsys->in['displayname'], $bugsys->in['email']);
99 $mail->set('subject', sprintf(_('Welcome to %1$s'), $bugsys->options['trackertitle']));
100 $mail->set('bodytext', sprintf(_('Hi %1$s,
101
102 Welcome to the %2$s tracker. Before you can begin posting bug reports, you\'ll need to activae your account. To do this, please click this link:
103
104 %3$s/register.php?do=activate&userid=%4$s&activator=%5$s'),
105
106 $bugsys->in['displayname'],
107 $bugsys->options['trackertitle'],
108 $bugsys->options['trackerurl'],
109 $userid,
110 $activationid
111 ));
112
113 $mail->send();
114
115 $message->message(_('You now need to activate your account via email.'));
116 }
117 else if ($usergroupid == 4 OR $usergroupid == 2)
118 {
119 if ($bugsys->options['sendwelcomemail'])
120 {
121 $mail->to_add($bugsys->in['displayname'], $bugsys->in['email']);
122 $mail->set('subject', sprintf(_('Welcome to %1$s'), $bugsys->options['trackertitle']));
123 $mail->set('bodytext', sprintf(_('Hi %1$s,
124
125 Thank you for taking the time to register at %2$s. We look forward to your contributations to making our products better.
126
127 If you have any questions, please don\'t hesitate to contact the webmaster.'),
128 $bugsys->in['displayname'],
129 $bugsys->options['trackertitle']
130 ));
131
132 $mail->send();
133 }
134
135 if ($usergroupid == 4)
136 {
137 $message->message(_('Your account is pending approval.'));
138 }
139 else
140 {
141 $message->message(_('Thank you for registering. You may now use your account.'));
142 }
143 }
144 }
145 else
146 {
147 $_REQUEST['do'] = '';
148 $show['errors'] = true;
149 $message->error_list_process();
150 }
151 }
152
153 // ###################################################################
154
155 if (empty($_REQUEST['do']))
156 {
157 if ($bugsys->userinfo['userid'])
158 {
159 $message->error(_('Sorry, you are already registered.'));
160 }
161
162 if (!$bugsys->options['allownewreg'])
163 {
164 $message->error(_('Sorry, we don\'t allow new registrations.'));
165 }
166
167 foreach ($bugsys->datastore['language'] AS $value => $temp)
168 {
169 $label = $temp['title'];
170 $selected = ($value == $bugsys->in['languageid']);
171 eval('$opts .= "' . $template->fetch('selectoption') . '";');
172 }
173
174 eval('$template->flush("' . $template->fetch('register') . '");');
175 }
176
177 // ###################################################################
178
179 if ($_REQUEST['do'] == 'activate')
180 {
181 $bugsys->input_clean('userid', TYPE_UINT);
182 if ($useractivation = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "useractivation WHERE userid = " . $bugsys->in['userid'] . " AND activator = '" . $bugsys->in['activator'] . "'"))
183 {
184 $user = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = " . $bugsys->in['userid']);
185 $db->query("UPDATE " . TABLE_PREFIX . "user SET usergroupid = $useractivation[usergroupid] WHERE userid = " . $bugsys->in['userid']);
186 $db->query("DELETE FROM " . TABLE_PREFIX . "useractivation WHERE userid = " . $bugsys->in['userid']);
187
188 if ($bugsys->options['sendwelcomemail'])
189 {
190 $mail->to_add($user['displayname'], $user['email']);
191 $mail->set('subject', sprintf(_('Welcome to %1$s'), $bugsys->options['trackertitle']));
192 $mail->set('bodytext', sprintf(_('Hi %1$s,
193
194 Thank you for taking the time to register at %2$s. We look forward to your contributations to making our products better.
195
196 If you have any questions, please don\'t hesitate to contact the webmaster.'),
197 $user['displayname'],
198 $bugsys->options['trackertitle']
199 ));
200 $mail->send();
201 }
202
203 $message->message(_('Your account is now activated and you can now login.'));
204 }
205 else
206 {
207 $message->error(_('Sorry, we could not match your registration string. Please make sure you entered the correct URL.'));
208 }
209 }
210
211 /*=====================================================================*\
212 || ###################################################################
213 || # $HeadURL$
214 || # $Id$
215 || ###################################################################
216 \*=====================================================================*/
217 ?>