r553: Force unique display name
[bugdar.git] / register.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 $fetchtemplates = array(
14 'register'
15 );
16
17 define('SVN', '$Id$');
18
19 $focus['user'] = 'focus';
20
21 require_once('./global.php');
22
23 // ###################################################################
24
25 if (empty($_REQUEST['do']))
26 {
27 if ($bugsys->userinfo['userid'])
28 {
29 $message->error($lang->string('Sorry, you are already registered.'));
30 }
31
32 if (!$bugsys->options['allownewreg'])
33 {
34 $message->error($lang->string('Sorry, we don\'t allow new registrations.'));
35 }
36
37 foreach ($bugsys->datastore['language'] AS $value => $temp)
38 {
39 $label = $temp['title'];
40 eval('$opts .= "' . $template->fetch('selectoption') . '";');
41 }
42
43 eval('$template->flush("' . $template->fetch('register') . '");');
44 }
45
46 // ###################################################################
47
48 if ($_POST['do'] == 'insert')
49 {
50 if ($bugsys->userinfo['userid'])
51 {
52 $message->error($lang->string('Sorry, you are already registered.'));
53 }
54
55 if (!$bugsys->options['allownewreg'])
56 {
57 $message->error($lang->string('Sorry, we don\'t allow new registrations.'));
58 }
59
60 if ($bugsys->in['email'] != $bugsys->in['confirmemail'])
61 {
62 $message->phrase[] = $lang->string('The emails you entered do not match.');
63 }
64
65 if (!$bugsys->in['email'])
66 {
67 $message->phrase[] = $lang->string('The email you specified was blank.');
68 }
69
70 if ($bugsys->in['password'] != $bugsys->in['confirmpassword'])
71 {
72 $message->phrase[] = $lang->string('The passwords you entered did not match.');
73 }
74
75 if (!$bugsys->in['password'])
76 {
77 $message->phrase[] = $lang->string('The password you specified was blank.');
78 }
79
80 if (!$funct->is_valid_email($bugsys->in['email']))
81 {
82 $message->phrase[] = $lang->string('The specified email is invalid.');
83 }
84
85 if (is_array($db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE email = '" . $bugsys->in['email'] . "'")))
86 {
87 $message->phrase[] = $lang->string('The specified email is already in use.');
88 }
89
90 if (is_array($db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE displayname = '" . $bugsys->in['displayname'] . "'")))
91 {
92 $message->phrase[] = $lang->string('That display name is already in use by another user');
93 }
94
95 if ($message->phrase)
96 {
97 $message->error_list_process();
98 $message->error();
99 }
100
101 $salt = $funct->rand(15);
102
103 if ($bugsys->options['verifyemail'])
104 {
105 $usergroupid = 3;
106 }
107 else
108 {
109 if ($bugsys->options['moderatenewusers'])
110 {
111 $usergroupid = 4;
112 }
113 else
114 {
115 $usergroupid = 2;
116 }
117 }
118
119 $db->query("
120 INSERT INTO " . TABLE_PREFIX . "user
121 (email, displayname, password, salt, authkey, showemail, showcolours, languageid, usergroupid)
122 VALUES
123 ('" . $bugsys->in['email'] . "',
124 '" . $bugsys->in['displayname'] . "',
125 '" . md5(md5($bugsys->in['password']) . md5($salt)) . "',
126 '$salt',
127 '" . $funct->rand() . "',
128 " . intval($bugsys->in['showemail']) . ",
129 1,
130 " . intval($bugsys->in['languageid']) . ",
131 $usergroupid
132 )"
133 );
134
135 $userid = $db->insert_id();
136
137 // Verify email address
138 if ($usergroupid == 3)
139 {
140 $activationid = $funct->rand(25);
141
142 $db->query("INSERT INTO " . TABLE_PREFIX . "useractivation (userid, activator, dateline, usergroupid) VALUES ($userid, '$activationid', " . TIMENOW . ", 2)");
143
144 $mail->to = $bugsys->in['email'];
145 $mail->subject = sprintf($lang->string('Welcome to %1$s'), $bugsys->options['trackertitle']);
146 $mail->body = sprintf($lang->string('Hi %1$s,
147
148 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:
149
150 %3$s/register.php?do=activate&userid=%4$s&activator=%5$s'),
151
152 $bugsys->in['displayname'],
153 $bugsys->options['trackertitle'],
154 $bugsys->options['trackerurl'],
155 $userid,
156 $activationid
157 );
158
159 $mail->send();
160
161 $message->message($lang->string('You now need to activate your account via email.'));
162 }
163 else if ($usergroupid == 4 OR $usergroupid == 2)
164 {
165 if ($bugsys->options['sendwelcomemail'])
166 {
167 $mail->to = $bugsys->in['email'];
168 $mail->subject = sprintf($lang->string('Welcome to %1$s'), $bugsys->options['trackertitle']);
169 $mail->body = sprintf($lang->string('Hi %1$s,
170
171 Thank you for taking the time to register at %2$s. We look forward to your contributations to making our products better.
172
173 If you have any questions, please don\'t hesitate to contact the webmaster.'),
174 $bugsys->in['displayname'],
175 $bugsys->options['trackertitle']
176 );
177
178 $mail->send();
179 }
180
181 if ($usergroupid == 4)
182 {
183 $message->message($lang->string('Your account is pending approval.'));
184 }
185 else
186 {
187 $message->message($lang->string('Thank you for registering. You may now use your account.'));
188 }
189 }
190 }
191
192 // ###################################################################
193
194 if ($_REQUEST['do'] == 'activate')
195 {
196 if ($useractivation = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "useractivation WHERE userid = " . intval($bugsys->in['userid']) . " AND activator = '" . $bugsys->in['activator'] . "'"))
197 {
198 $user = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = " . intval($bugsys->in['userid']));
199 $db->query("UPDATE " . TABLE_PREFIX . "user SET usergroupid = $useractivation[usergroupid] WHERE userid = " . intval($bugsys->in['userid']));
200 $db->query("DELETE FROM " . TABLE_PREFIX . "useractivation WHERE userid = " . intval($bugsys->in['userid']));
201
202 if ($bugsys->options['sendwelcomemail'])
203 {
204 $mail->to = $user['email'];
205 $mail->subject = sprintf($lang->string('Welcome to %1$s'), $bugsys->options['trackertitle']);
206 $mail->body = sprintf($lang->string('Hi %1$s,
207
208 Thank you for taking the time to register at %2$s. We look forward to your contributations to making our products better.
209
210 If you have any questions, please don\'t hesitate to contact the webmaster.'),
211 $user['displayname'],
212 $bugsys->options['trackertitle']
213 );
214 $mail->send();
215 }
216
217 $message->message($lang->string('Your account is now activated and you can now login.'));
218 }
219 else
220 {
221 $message->error($lang->string('Sorry, we could not match your registration string. Please make sure you entered the correct URL.'));
222 }
223 }
224
225 /*=====================================================================*\
226 || ###################################################################
227 || # $HeadURL$
228 || # $Id$
229 || ###################################################################
230 \*=====================================================================*/
231 ?>