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