- Get the email system to work for register.php
[bugdar.git] / register.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright ©2002-2007 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 2 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 // ###################################################################
34
35 if ($_POST['do'] == 'insert')
36 {
37 if (bugdar::$userinfo['userid'])
38 {
39 $message->error(T('Sorry, you are already registered.'));
40 }
41
42 if (!bugdar::$options['allownewreg'])
43 {
44 $message->error(T('Sorry, we don\'t allow new registrations.'));
45 }
46
47 if ($input->in['email'] != $input->in['confirmemail'])
48 {
49 $message->addError(T('The emails you entered do not match.'));
50 }
51
52 if ($input->in['password'] != $input->in['confirmpassword'])
53 {
54 $message->addError(T('The passwords you entered did not match.'));
55 }
56
57 if (bugdar::$options['verifyemail'])
58 {
59 $usergroupid = 3;
60 }
61 else
62 {
63 if (bugdar::$options['moderatenewusers'])
64 {
65 $usergroupid = 4;
66 }
67 else
68 {
69 $usergroupid = 2;
70 }
71 }
72
73 $user = new UserAPI();
74 $user->set('email', $input->in['email']);
75 $user->set('displayname', $input->in['displayname']);
76 $user->set('password', $input->in['password']);
77 $user->set('showemail', $input->in['showemail']);
78 $user->set('showcolors', 1);
79 $user->set('languageid', $input->in['languageid']);
80 $user->set('timezone', bugdar::$options['defaulttimezone']);
81 $user->set('usergroupid', $usergroupid);
82
83 if (!$message->hasErrors())
84 {
85 $user->insert();
86
87 $userid = $user->insertid;
88
89 // Verify email address
90 if ($usergroupid == 3)
91 {
92 $activationid = BSFunctions::random(25);
93
94 $db->query("INSERT INTO " . TABLE_PREFIX . "useractivation (userid, activator, dateline, usergroupid) VALUES ($userid, '$activationid', " . TIMENOW . ", 2)");
95
96 $email = get_email_text('activate_account');
97 $mail = new BSMail();
98 $mail->setSubject($email['subject']);
99 $mail->setBodyText(sprintf($email['bodyText'], $input->in['displayname'], bugdar::$options['trackertitle'], bugdar::$options['trackerurl'], $userid, $activationid));
100 $mail->setFromAddress(MAIL_FROM_ADDRESS);
101 $mail->setFromName(MAIL_FROM_NAME);
102 $mail->send($input->in['email'], $input->in['displayname']);
103
104 $message->message(T('You now need to activate your account via email.'));
105 }
106 else if ($usergroupid == 4 OR $usergroupid == 2)
107 {
108 if (bugdar::$options['sendwelcomemail'])
109 {
110 $displayName = $input->in['displayname'];
111
112 $email = get_email_text('welcome');
113 $mail = new BSMail();
114 $mail->setSubject($email['subject']);
115 $mail->setBodyText(sprintf($email['bodyText'], $input->in['displayname'], bugdar::$options['trackertitle']));
116 $mail->setFromAddress(MAIL_FROM_ADDRESS);
117 $mail->setFromName(MAIL_FROM_NAME);
118 $mail->send($input->in['email'], $input->in['displayname']);
119 }
120
121 if ($usergroupid == 4)
122 {
123 $message->message(T('Your account is pending approval.'));
124 }
125 else
126 {
127 $message->message(T('Thank you for registering. You may now use your account.'));
128 }
129 }
130 }
131 else
132 {
133 $_REQUEST['do'] = '';
134 $show['errors'] = true;
135 }
136 }
137
138 // ###################################################################
139
140 if (empty($_REQUEST['do']))
141 {
142 if (bugdar::$userinfo['userid'])
143 {
144 $message->error(T('Sorry, you are already registered.'));
145 }
146
147 if (!bugdar::$options['allownewreg'])
148 {
149 $message->error(T('Sorry, we don\'t allow new registrations.'));
150 }
151
152 foreach (bugdar::$datastore['language'] as $value => $temp)
153 {
154 $tpl = new BSTemplate('selectoption');
155 $tpl->vars = array(
156 'value' => $value,
157 'label' => $temp['title'],
158 'selected' => ($value == $input->in['languageid'])
159 );
160 $opts .= $tpl->evaluate()->getTemplate();
161 }
162
163 $tpl = new BSTemplate('register');
164 $tpl->vars = array(
165 'opts' => $opts
166 );
167 $tpl->evaluate()->flush();
168 }
169
170 // ###################################################################
171
172 if ($_REQUEST['do'] == 'activate')
173 {
174 $input->inputClean('userid', TYPE_UINT);
175 if ($useractivation = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "useractivation WHERE userid = " . $input->in['userid'] . " AND activator = '" . $input->inputEscape('activator') . "'"))
176 {
177 $user = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = " . $input->in['userid']);
178 $db->query("UPDATE " . TABLE_PREFIX . "user SET usergroupid = $useractivation[usergroupid] WHERE userid = " . $input->in['userid']);
179 $db->query("DELETE FROM " . TABLE_PREFIX . "useractivation WHERE userid = " . $input->in['userid']);
180
181 if (bugdar::$options['sendwelcomemail'])
182 {
183 $displayName = $user['displayname'];
184
185 $email = get_email_text('welcome');
186 $mail = new BSMail();
187 $mail->setSubject($email['subject']);
188 $mail->setBodyText(sprintf($email['bodyText'], $user['displayname'], bugdar::$options['trackertitle']));
189 $mail->setFromAddress(MAIL_FROM_ADDRESS);
190 $mail->setFromName(MAIL_FROM_NAME);
191 $mail->send($user['email'], $user['displayname']);
192 }
193
194 $message->message(T('Your account is now activated and you can now login.'));
195 }
196 else
197 {
198 $message->error(T('Sorry, we could not match your registration string. Please make sure you entered the correct URL.'));
199 }
200 }
201
202 /*=====================================================================*\
203 || ###################################################################
204 || # $HeadURL$
205 || # $Id$
206 || ###################################################################
207 \*=====================================================================*/
208 ?>