r304: Added tab navigation system.
[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 ($bugsys->userinfo['userid'])
26 {
27 $message->error('Sorry, you are already registered!');
28 }
29
30 if (!$bugsys->options['allownewreg'])
31 {
32 $message->error('Sorry, we don\'t allow new registrations!');
33 }
34
35 // ###################################################################
36
37 if (empty($_REQUEST['do']))
38 {
39 foreach ($bugsys->datastore['language'] AS $value => $temp)
40 {
41 $label = $temp['title'];
42 eval('$opts .= "' . $template->fetch('selectoption') . '";');
43 }
44
45 eval('$template->flush("' . $template->fetch('register') . '");');
46 }
47
48 // ###################################################################
49
50 if ($_POST['do'] == 'insert')
51 {
52 if ($bugsys->in['email'] != $bugsys->in['confirmemail'])
53 {
54 $error->phrase[] = 'The emails you entered do not match.';
55 }
56
57 if (!$bugsys->in['email'])
58 {
59 $error->phrase[] = 'The password you specified was blank.';
60 }
61
62 if ($bugsys->in['password'] != $bugsys->in['confirmpassword'])
63 {
64 $error->phrase[] = 'The passwords you entered did not match.';
65 }
66
67 if (!$bugsys->in['password'])
68 {
69 $error->phrase[] = 'The password you specified was blank.';
70 }
71
72 if (!$funct->is_valid_email($bugsys->in['email']))
73 {
74 $error->phrase[] = 'The specified email is invalid.';
75 }
76
77 if (is_array($db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE email = '" . $bugsys->in['email'] . "'")))
78 {
79 $error->phrase[] = 'The specified email is already in use.';
80 }
81
82 $message->error_list_process();
83 $message->error();
84
85 $salt = $funct->rand(15);
86
87 if ($bugsys->options['verifyemail'])
88 {
89 $usergroupid = 3;
90 }
91 else
92 {
93 if ($bugsys->options['moderatenewusers'])
94 {
95 $usergroupid = 4;
96 }
97 else
98 {
99 $usergroupid = 2;
100 }
101 }
102
103 $db->query("
104 INSERT INTO " . TABLE_PREFIX . "user
105 (email, displayname, password, salt, authkey, showemail, languageid, usergroupid)
106 VALUES
107 ('" . $bugsys->in['email'] . "',
108 '" . $bugsys->in['displayname'] . "',
109 '" . md5(md5($bugsys->in['password']) . md5($salt)) . "',
110 '$salt',
111 '" . $funct->rand() . "',
112 " . intval($bugsys->in['showemail']) . ",
113 " . intval($bugsys->in['languageid']) . ",
114 $usergroupid
115 )"
116 );
117
118 $userid = $db->insert_id();
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', " . NOW . ", 2)");
126
127 $mail->to = $bugsys->in['email'];
128 $mail->subject = 'Welcome to ' . $bugsys->options['trackertitle'];
129 $mail->body = "Hi " . $bugsys->in['displayname'] . " you need to activate your account: http://devbox/bugtraq/register.php?do=activate&userid=" . $userid . "&activator=" . $activationid;
130 $mail->send();
131
132 $message->message('You now need to activate your account via email.');
133 }
134 else if ($usergroupid == 4 OR $usergroupid == 2)
135 {
136 if ($bugsys->options['sendwelcomemail'])
137 {
138 $mail->to = $bugsys->in['email'];
139 $mail->subject = 'Welcome to ' . $bugsys->options['trackertitle'];
140 $mail->body = "Hi " . $bugsys->in['displayname'] . " and welcome to the " . $bugsys->options['trackertitle'] . " bug tracker! Thanks for registering.";
141 $mail->send();
142 }
143
144 if ($usergroupid == 4)
145 {
146 $message->message('Your account is pending approval.');
147 }
148 else
149 {
150 $message->message('Registration complete!');
151 }
152 }
153 }
154
155 // ###################################################################
156
157 if ($_REQUEST['do'] == 'activate')
158 {
159 if ($useractivation = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "useractivation WHERE userid = " . intval($bugsys->in['userid']) . " AND activator = '" . $bugsys->in['activator'] . "'"))
160 {
161 $db->query("UPDATE " . TABLE_PREFIX . "user SET usergroupid = $useractivation[usergroupid] WHERE userid = " . intval($bugsys->in['userid']));
162 $db->query("DELETE FROM " . TABLE_PREFIX . "useractivation WHERE userid = " . intval($bugsys->in['userid']));
163 $message->message('your account is now activated and you can now login');
164 }
165 else
166 {
167 $message->error('we could not match your registration string. please make sure you entered the correct url');
168 }
169 }
170
171 /*=====================================================================*\
172 || ###################################################################
173 || # $HeadURL$
174 || # $Id$
175 || ###################################################################
176 \*=====================================================================*/
177 ?>