source: trunk/forum/includes/ucp/ucp_register.php

Last change on this file was 702, checked in by george, 15 years ago
  • Upraveno: Aktualizace fóra.
File size: 15.1 KB
Line 
1<?php
2/**
3*
4* @package ucp
5* @version $Id$
6* @copyright (c) 2005 phpBB Group
7* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8*
9*/
10
11/**
12* @ignore
13*/
14if (!defined('IN_PHPBB'))
15{
16 exit;
17}
18
19/**
20* ucp_register
21* Board registration
22* @package ucp
23*/
24class ucp_register
25{
26 var $u_action;
27
28 function main($id, $mode)
29 {
30 global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
31
32 //
33 if ($config['require_activation'] == USER_ACTIVATION_DISABLE)
34 {
35 trigger_error('UCP_REGISTER_DISABLE');
36 }
37
38 include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
39
40 $coppa = (isset($_REQUEST['coppa'])) ? ((!empty($_REQUEST['coppa'])) ? 1 : 0) : false;
41 $agreed = (!empty($_POST['agreed'])) ? 1 : 0;
42 $submit = (isset($_POST['submit'])) ? true : false;
43 $change_lang = request_var('change_lang', '');
44 $user_lang = request_var('lang', $user->lang_name);
45
46 if ($agreed)
47 {
48 add_form_key('ucp_register');
49 }
50 else
51 {
52 add_form_key('ucp_register_terms');
53 }
54
55 if ($change_lang || $user_lang != $config['default_lang'])
56 {
57 $use_lang = ($change_lang) ? basename($change_lang) : basename($user_lang);
58
59 if (file_exists($user->lang_path . $use_lang . '/'))
60 {
61 if ($change_lang)
62 {
63 $submit = false;
64
65 // Setting back agreed to let the user view the agreement in his/her language
66 $agreed = (empty($_GET['change_lang'])) ? 0 : $agreed;
67 }
68
69 $user->lang_name = $user_lang = $use_lang;
70 $user->lang = array();
71 $user->data['user_lang'] = $user->lang_name;
72 $user->add_lang(array('common', 'ucp'));
73 }
74 else
75 {
76 $change_lang = '';
77 $user_lang = $user->lang_name;
78 }
79 }
80
81
82 $cp = new custom_profile();
83
84 $error = $cp_data = $cp_error = array();
85
86 if (!$agreed || ($coppa === false && $config['coppa_enable']) || ($coppa && !$config['coppa_enable']))
87 {
88 $add_lang = ($change_lang) ? '&amp;change_lang=' . urlencode($change_lang) : '';
89 $add_coppa = ($coppa !== false) ? '&amp;coppa=' . $coppa : '';
90
91 $s_hidden_fields = array(
92 'change_lang' => $change_lang,
93 );
94
95 // If we change the language, we want to pass on some more possible parameter.
96 if ($change_lang)
97 {
98 // We do not include the password
99 $s_hidden_fields = array_merge($s_hidden_fields, array(
100 'username' => utf8_normalize_nfc(request_var('username', '', true)),
101 'email' => strtolower(request_var('email', '')),
102 'email_confirm' => strtolower(request_var('email_confirm', '')),
103 'lang' => $user->lang_name,
104 'tz' => request_var('tz', (float) $config['board_timezone']),
105 ));
106
107 }
108
109 // Checking amount of available languages
110 $sql = 'SELECT lang_id
111 FROM ' . LANG_TABLE;
112 $result = $db->sql_query($sql);
113
114 $lang_row = array();
115 while ($row = $db->sql_fetchrow($result))
116 {
117 $lang_row[] = $row;
118 }
119 $db->sql_freeresult($result);
120
121 if ($coppa === false && $config['coppa_enable'])
122 {
123 $now = getdate();
124 $coppa_birthday = $user->format_date(mktime($now['hours'] + $user->data['user_dst'], $now['minutes'], $now['seconds'], $now['mon'], $now['mday'] - 1, $now['year'] - 13), $user->lang['DATE_FORMAT']);
125 unset($now);
126
127 $template->assign_vars(array(
128 'S_LANG_OPTIONS' => (sizeof($lang_row) > 1) ? language_select($user_lang) : '',
129 'L_COPPA_NO' => sprintf($user->lang['UCP_COPPA_BEFORE'], $coppa_birthday),
130 'L_COPPA_YES' => sprintf($user->lang['UCP_COPPA_ON_AFTER'], $coppa_birthday),
131
132 'U_COPPA_NO' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register&amp;coppa=0' . $add_lang),
133 'U_COPPA_YES' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register&amp;coppa=1' . $add_lang),
134
135 'S_SHOW_COPPA' => true,
136 'S_HIDDEN_FIELDS' => build_hidden_fields($s_hidden_fields),
137 'S_UCP_ACTION' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register' . $add_lang),
138 ));
139 }
140 else
141 {
142 $template->assign_vars(array(
143 'S_LANG_OPTIONS' => (sizeof($lang_row) > 1) ? language_select($user_lang) : '',
144 'L_TERMS_OF_USE' => sprintf($user->lang['TERMS_OF_USE_CONTENT'], $config['sitename'], generate_board_url()),
145
146 'S_SHOW_COPPA' => false,
147 'S_REGISTRATION' => true,
148 'S_HIDDEN_FIELDS' => build_hidden_fields($s_hidden_fields),
149 'S_UCP_ACTION' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register' . $add_lang . $add_coppa),
150 )
151 );
152 }
153 unset($lang_row);
154
155 $this->tpl_name = 'ucp_agreement';
156 return;
157 }
158
159
160 // The CAPTCHA kicks in here. We can't help that the information gets lost on language change.
161 if ($config['enable_confirm'])
162 {
163 include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
164 $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
165 $captcha->init(CONFIRM_REG);
166 }
167
168 // Try to manually determine the timezone and adjust the dst if the server date/time complies with the default setting +/- 1
169 $timezone = date('Z') / 3600;
170 $is_dst = date('I');
171
172 if ($config['board_timezone'] == $timezone || $config['board_timezone'] == ($timezone - 1))
173 {
174 $timezone = ($is_dst) ? $timezone - 1 : $timezone;
175
176 if (!isset($user->lang['tz_zones'][(string) $timezone]))
177 {
178 $timezone = $config['board_timezone'];
179 }
180 }
181 else
182 {
183 $is_dst = $config['board_dst'];
184 $timezone = $config['board_timezone'];
185 }
186
187 $data = array(
188 'username' => utf8_normalize_nfc(request_var('username', '', true)),
189 'new_password' => request_var('new_password', '', true),
190 'password_confirm' => request_var('password_confirm', '', true),
191 'email' => strtolower(request_var('email', '')),
192 'email_confirm' => strtolower(request_var('email_confirm', '')),
193 'lang' => basename(request_var('lang', $user->lang_name)),
194 'tz' => request_var('tz', (float) $timezone),
195 );
196
197 // Check and initialize some variables if needed
198 if ($submit)
199 {
200 $error = validate_data($data, array(
201 'username' => array(
202 array('string', false, $config['min_name_chars'], $config['max_name_chars']),
203 array('username', '')),
204 'new_password' => array(
205 array('string', false, $config['min_pass_chars'], $config['max_pass_chars']),
206 array('password')),
207 'password_confirm' => array('string', false, $config['min_pass_chars'], $config['max_pass_chars']),
208 'email' => array(
209 array('string', false, 6, 60),
210 array('email')),
211 'email_confirm' => array('string', false, 6, 60),
212 'tz' => array('num', false, -14, 14),
213 'lang' => array('match', false, '#^[a-z_\-]{2,}$#i'),
214 ));
215
216 if (!check_form_key('ucp_register'))
217 {
218 $error[] = $user->lang['FORM_INVALID'];
219 }
220
221 // Replace "error" strings with their real, localised form
222 $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
223
224 if ($config['enable_confirm'])
225 {
226 $vc_response = $captcha->validate($data);
227 if ($vc_response !== false)
228 {
229 $error[] = $vc_response;
230 }
231
232 if ($config['max_reg_attempts'] && $captcha->get_attempt_count() > $config['max_reg_attempts'])
233 {
234 $error[] = $user->lang['TOO_MANY_REGISTERS'];
235 }
236 }
237
238 // DNSBL check
239 if ($config['check_dnsbl'])
240 {
241 if (($dnsbl = $user->check_dnsbl('register')) !== false)
242 {
243 $error[] = sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]);
244 }
245 }
246
247 // validate custom profile fields
248 $cp->submit_cp_field('register', $user->get_iso_lang_id(), $cp_data, $error);
249
250 if (!sizeof($error))
251 {
252 if ($data['new_password'] != $data['password_confirm'])
253 {
254 $error[] = $user->lang['NEW_PASSWORD_ERROR'];
255 }
256
257 if ($data['email'] != $data['email_confirm'])
258 {
259 $error[] = $user->lang['NEW_EMAIL_ERROR'];
260 }
261 }
262
263 if (!sizeof($error))
264 {
265 $server_url = generate_board_url();
266
267 // Which group by default?
268 $group_name = ($coppa) ? 'REGISTERED_COPPA' : 'REGISTERED';
269
270 $sql = 'SELECT group_id
271 FROM ' . GROUPS_TABLE . "
272 WHERE group_name = '" . $db->sql_escape($group_name) . "'
273 AND group_type = " . GROUP_SPECIAL;
274 $result = $db->sql_query($sql);
275 $row = $db->sql_fetchrow($result);
276 $db->sql_freeresult($result);
277
278 if (!$row)
279 {
280 trigger_error('NO_GROUP');
281 }
282
283 $group_id = $row['group_id'];
284
285 if (($coppa ||
286 $config['require_activation'] == USER_ACTIVATION_SELF ||
287 $config['require_activation'] == USER_ACTIVATION_ADMIN) && $config['email_enable'])
288 {
289 $user_actkey = gen_rand_string(10);
290 $key_len = 54 - (strlen($server_url));
291 $key_len = ($key_len < 6) ? 6 : $key_len;
292 $user_actkey = substr($user_actkey, 0, $key_len);
293
294 $user_type = USER_INACTIVE;
295 $user_inactive_reason = INACTIVE_REGISTER;
296 $user_inactive_time = time();
297 }
298 else
299 {
300 $user_type = USER_NORMAL;
301 $user_actkey = '';
302 $user_inactive_reason = 0;
303 $user_inactive_time = 0;
304 }
305
306 $user_row = array(
307 'username' => $data['username'],
308 'user_password' => phpbb_hash($data['new_password']),
309 'user_email' => $data['email'],
310 'group_id' => (int) $group_id,
311 'user_timezone' => (float) $data['tz'],
312 'user_dst' => $is_dst,
313 'user_lang' => $data['lang'],
314 'user_type' => $user_type,
315 'user_actkey' => $user_actkey,
316 'user_ip' => $user->ip,
317 'user_regdate' => time(),
318 'user_inactive_reason' => $user_inactive_reason,
319 'user_inactive_time' => $user_inactive_time,
320 );
321
322 if ($config['new_member_post_limit'])
323 {
324 $user_row['user_new'] = 1;
325 }
326
327 // Register user...
328 $user_id = user_add($user_row, $cp_data);
329
330 // This should not happen, because the required variables are listed above...
331 if ($user_id === false)
332 {
333 trigger_error('NO_USER', E_USER_ERROR);
334 }
335
336 // Okay, captcha, your job is done.
337 if ($config['enable_confirm'] && isset($captcha))
338 {
339 $captcha->reset();
340 }
341
342 if ($coppa && $config['email_enable'])
343 {
344 $message = $user->lang['ACCOUNT_COPPA'];
345 $email_template = 'coppa_welcome_inactive';
346 }
347 else if ($config['require_activation'] == USER_ACTIVATION_SELF && $config['email_enable'])
348 {
349 $message = $user->lang['ACCOUNT_INACTIVE'];
350 $email_template = 'user_welcome_inactive';
351 }
352 else if ($config['require_activation'] == USER_ACTIVATION_ADMIN && $config['email_enable'])
353 {
354 $message = $user->lang['ACCOUNT_INACTIVE_ADMIN'];
355 $email_template = 'admin_welcome_inactive';
356 }
357 else
358 {
359 $message = $user->lang['ACCOUNT_ADDED'];
360 $email_template = 'user_welcome';
361 }
362
363 if ($config['email_enable'])
364 {
365 include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
366
367 $messenger = new messenger(false);
368
369 $messenger->template($email_template, $data['lang']);
370
371 $messenger->to($data['email'], $data['username']);
372
373 $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
374 $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
375 $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
376 $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
377
378 $messenger->assign_vars(array(
379 'WELCOME_MSG' => htmlspecialchars_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename'])),
380 'USERNAME' => htmlspecialchars_decode($data['username']),
381 'PASSWORD' => htmlspecialchars_decode($data['new_password']),
382 'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u=$user_id&k=$user_actkey")
383 );
384
385 if ($coppa)
386 {
387 $messenger->assign_vars(array(
388 'FAX_INFO' => $config['coppa_fax'],
389 'MAIL_INFO' => $config['coppa_mail'],
390 'EMAIL_ADDRESS' => $data['email'])
391 );
392 }
393
394 $messenger->send(NOTIFY_EMAIL);
395
396 if ($config['require_activation'] == USER_ACTIVATION_ADMIN)
397 {
398 // Grab an array of user_id's with a_user permissions ... these users can activate a user
399 $admin_ary = $auth->acl_get_list(false, 'a_user', false);
400 $admin_ary = (!empty($admin_ary[0]['a_user'])) ? $admin_ary[0]['a_user'] : array();
401
402 // Also include founders
403 $where_sql = ' WHERE user_type = ' . USER_FOUNDER;
404
405 if (sizeof($admin_ary))
406 {
407 $where_sql .= ' OR ' . $db->sql_in_set('user_id', $admin_ary);
408 }
409
410 $sql = 'SELECT user_id, username, user_email, user_lang, user_jabber, user_notify_type
411 FROM ' . USERS_TABLE . ' ' .
412 $where_sql;
413 $result = $db->sql_query($sql);
414
415 while ($row = $db->sql_fetchrow($result))
416 {
417 $messenger->template('admin_activate', $row['user_lang']);
418 $messenger->to($row['user_email'], $row['username']);
419 $messenger->im($row['user_jabber'], $row['username']);
420
421 $messenger->assign_vars(array(
422 'USERNAME' => htmlspecialchars_decode($data['username']),
423 'U_USER_DETAILS' => "$server_url/memberlist.$phpEx?mode=viewprofile&u=$user_id",
424 'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u=$user_id&k=$user_actkey")
425 );
426
427 $messenger->send($row['user_notify_type']);
428 }
429 $db->sql_freeresult($result);
430 }
431 }
432
433 $message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
434 trigger_error($message);
435 }
436 }
437
438 $s_hidden_fields = array(
439 'agreed' => 'true',
440 'change_lang' => 0,
441 );
442
443 if ($config['coppa_enable'])
444 {
445 $s_hidden_fields['coppa'] = $coppa;
446 }
447
448 if ($config['enable_confirm'])
449 {
450 $s_hidden_fields = array_merge($s_hidden_fields, $captcha->get_hidden_fields());
451 }
452 $s_hidden_fields = build_hidden_fields($s_hidden_fields);
453 $confirm_image = '';
454
455 // Visual Confirmation - Show images
456 if ($config['enable_confirm'])
457 {
458 $template->assign_vars(array(
459 'CAPTCHA_TEMPLATE' => $captcha->get_template(),
460 ));
461 }
462
463 //
464 $l_reg_cond = '';
465 switch ($config['require_activation'])
466 {
467 case USER_ACTIVATION_SELF:
468 $l_reg_cond = $user->lang['UCP_EMAIL_ACTIVATE'];
469 break;
470
471 case USER_ACTIVATION_ADMIN:
472 $l_reg_cond = $user->lang['UCP_ADMIN_ACTIVATE'];
473 break;
474 }
475
476 $template->assign_vars(array(
477 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
478 'USERNAME' => $data['username'],
479 'PASSWORD' => $data['new_password'],
480 'PASSWORD_CONFIRM' => $data['password_confirm'],
481 'EMAIL' => $data['email'],
482 'EMAIL_CONFIRM' => $data['email_confirm'],
483
484 'L_REG_COND' => $l_reg_cond,
485 'L_USERNAME_EXPLAIN' => sprintf($user->lang[$config['allow_name_chars'] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']),
486 'L_PASSWORD_EXPLAIN' => sprintf($user->lang[$config['pass_complex'] . '_EXPLAIN'], $config['min_pass_chars'], $config['max_pass_chars']),
487
488 'S_LANG_OPTIONS' => language_select($data['lang']),
489 'S_TZ_OPTIONS' => tz_select($data['tz']),
490 'S_CONFIRM_REFRESH' => ($config['enable_confirm'] && $config['confirm_refresh']) ? true : false,
491 'S_REGISTRATION' => true,
492 'S_COPPA' => $coppa,
493 'S_HIDDEN_FIELDS' => $s_hidden_fields,
494 'S_UCP_ACTION' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register'),
495 ));
496
497 //
498 $user->profile_fields = array();
499
500 // Generate profile fields -> Template Block Variable profile_fields
501 $cp->generate_profile_fields('register', $user->get_iso_lang_id());
502
503 //
504 $this->tpl_name = 'ucp_register';
505 $this->page_title = 'UCP_REGISTRATION';
506 }
507}
508
509?>
Note: See TracBrowser for help on using the repository browser.