r63: Updated initial copyright year from 2003 to 2002
[bugdar.git] / register.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Renapsus [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # All parts of this file are ©2002-[#]year[#] Iris Studios, Inc. No # ||
7 || # part of this file may be reproduced in any way: part or whole. # ||
8 || # --------------------------------------------------------------- # ||
9 || # ©2002 - [#]year[#] Iris Studios, Inc. | http://www.iris-studios.com # ||
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 echo 'Sorry, you are already registered!';
24 exit;
25 }
26
27 if (!$bugsys->options['allownewreg'])
28 {
29 echo 'Sorry, we don\'t allow new registrations!';
30 exit;
31 }
32
33 // ###################################################################
34
35 if (empty($_REQUEST['do']))
36 {
37 foreach ($bugsys->datastore['language'] AS $value => $temp)
38 {
39 $label = $temp['title'];
40 eval('$opts .= "' . $tpl->fetch('selectoption') . '";');
41 }
42
43 eval('$tpl->flush("' . $tpl->fetch('register') . '");');
44 }
45
46 // ###################################################################
47
48 if ($_POST['do'] == 'insert')
49 {
50 sanitize(array('email' => STR_NOHTML, 'confirmemail' => STR_NOHTML, 'displayname' => STR_NOHTML, 'password' => STR, 'confirmpassword' => STR, 'showemail' => INT, 'languageid' => INT));
51
52 if ($vars['email'] != $vars['confirmemail'])
53 {
54 $errors[] = 'The emails you entered do not match.';
55 }
56
57 if (!$vars['email'])
58 {
59 $errors[] = 'The password you specified was blank.';
60 }
61
62 if ($vars['password'] != $vars['confirmpassword'])
63 {
64 $errors[] = 'The passwords you entered did not match.';
65 }
66
67 if (!$vars['password'])
68 {
69 $errors[] = 'The password you specified was blank.';
70 }
71
72 if (is_array($DB_sql->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE email = '" . addslasheslike($vars['email']) . "'")))
73 {
74 $errors[] = 'The specified email is already in use.';
75 }
76
77 if (is_array($errors))
78 {
79 echo implode('<br />', $errors);
80 exit;
81 }
82
83 $salt = fetch_random_chars(15);
84
85 if ($bugsys->options['verifyemail'])
86 {
87 $usergroupid = 3;
88 }
89 else
90 {
91 if ($bugsys->options['moderatenewusers'])
92 {
93 $usergroupid = 4;
94 }
95 else
96 {
97 $usergroupid = 2;
98 }
99 }
100
101 $DB_sql->query("
102 INSERT INTO " . TABLE_PREFIX . "user
103 (email, displayname, password, salt, authkey, showemail, languageid, usergroupid)
104 VALUES
105 ('" . addslasheslike($vars['email']) . "',
106 '" . addslasheslike($vars['displayname']) . "',
107 '" . md5(md5($vars['password']) . md5($salt)) . "',
108 '$salt',
109 '" . fetch_random_chars() . "',
110 $vars[showemail],
111 $vars[languageid],
112 $usergroupid
113 )"
114 );
115
116 $userid = $DB_sql->insert_id();
117
118 // Verify email address
119 if ($usergroupid == 3)
120 {
121 $activationid = fetch_random_chars(25);
122
123 $DB_sql->query("INSERT INTO " . TABLE_PREFIX . "useractivation (userid, activator, dateline, usergroupid) VALUES ($userid, '$activationid', " . NOW . ", 2)");
124
125 mymail(addslasheslike($vars['email']), 'Welcome to ' . $bugsys->options['trackertitle'], "Hi " . addslasheslike($vars['displayname']) . " you need to activate your account: http://devbox/bugtraq/register.php?do=activate&userid=" . $userid . "&activator=" . $activationid);
126
127 echo 'You now need to activate your account via email.';
128 }
129 else if ($usergroupid == 4 OR $usergroupid == 2)
130 {
131 if ($bugsys->options['sendwelcomemail'])
132 {
133 mymail(addslasheslike($vars['email']), 'Welcome to ' . $bugsys->options['trackertitle'], "Hi " . addslasheslike($vars['displayname']) . " and welcome to the " . $bugsys->options['trackertitle'] . " bug tracker! Thanks for registering.");
134 }
135
136 if ($usergroupid == 4)
137 {
138 echo 'Your account is pending approval.';
139 }
140 else
141 {
142 echo 'Registration complete!';
143 }
144 }
145 }
146
147 // ###################################################################
148
149 if ($_REQUEST['do'] == 'activate')
150 {
151 sanitize(array('userid' => INT, 'activator' => STR));
152
153 if ($useractivation = $DB_sql->query_first("SELECT * FROM " . TABLE_PREFIX . "useractivation WHERE userid = $vars[userid] AND activator = '" . addslasheslike($vars['activator']) . "'"))
154 {
155 $DB_sql->query("UPDATE " . TABLE_PREFIX . "user SET usergroupid = $useractivation[usergroupid] WHERE userid = $vars[userid]");
156 $DB_sql->query("DELETE FROM " . TABLE_PREFIX . "useractivation WHERE userid = $vars[userid]");
157 echo 'your account is now activated and you can now login';
158 }
159 else
160 {
161 echo 'we could not match your registration string. please make sure you entered the correct url';
162 }
163 }
164
165 /*=====================================================================*\
166 || ###################################################################
167 || # $HeadURL$
168 || # $Id$
169 || ###################################################################
170 \*=====================================================================*/
171 ?>