[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 */ 14 if (!defined('IN_PHPBB')) 15 { 16 exit; 17 } 18 19 /** 20 * ucp_register 21 * Board registration 22 * @package ucp 23 */ 24 class 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 (!validate_language_iso_name($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) ? '&change_lang=' . urlencode($change_lang) : ''; 89 $add_coppa = ($coppa !== false) ? '&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&coppa=0' . $add_lang), 133 'U_COPPA_YES' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register&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 $is_dst = $config['board_dst']; 169 $timezone = $config['board_timezone']; 170 171 $data = array( 172 'username' => utf8_normalize_nfc(request_var('username', '', true)), 173 'new_password' => request_var('new_password', '', true), 174 'password_confirm' => request_var('password_confirm', '', true), 175 'email' => strtolower(request_var('email', '')), 176 'email_confirm' => strtolower(request_var('email_confirm', '')), 177 'lang' => basename(request_var('lang', $user->lang_name)), 178 'tz' => request_var('tz', (float) $timezone), 179 ); 180 181 // Check and initialize some variables if needed 182 if ($submit) 183 { 184 $error = validate_data($data, array( 185 'username' => array( 186 array('string', false, $config['min_name_chars'], $config['max_name_chars']), 187 array('username', '')), 188 'new_password' => array( 189 array('string', false, $config['min_pass_chars'], $config['max_pass_chars']), 190 array('password')), 191 'password_confirm' => array('string', false, $config['min_pass_chars'], $config['max_pass_chars']), 192 'email' => array( 193 array('string', false, 6, 60), 194 array('email')), 195 'email_confirm' => array('string', false, 6, 60), 196 'tz' => array('num', false, -14, 14), 197 'lang' => array('language_iso_name'), 198 )); 199 200 if (!check_form_key('ucp_register')) 201 { 202 $error[] = $user->lang['FORM_INVALID']; 203 } 204 205 // Replace "error" strings with their real, localised form 206 $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error); 207 208 if ($config['enable_confirm']) 209 { 210 $vc_response = $captcha->validate($data); 211 if ($vc_response !== false) 212 { 213 $error[] = $vc_response; 214 } 215 216 if ($config['max_reg_attempts'] && $captcha->get_attempt_count() > $config['max_reg_attempts']) 217 { 218 $error[] = $user->lang['TOO_MANY_REGISTERS']; 219 } 220 } 221 222 // DNSBL check 223 if ($config['check_dnsbl']) 224 { 225 if (($dnsbl = $user->check_dnsbl('register')) !== false) 226 { 227 $error[] = sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]); 228 } 229 } 230 231 // validate custom profile fields 232 $cp->submit_cp_field('register', $user->get_iso_lang_id(), $cp_data, $error); 233 234 if (!sizeof($error)) 235 { 236 if ($data['new_password'] != $data['password_confirm']) 237 { 238 $error[] = $user->lang['NEW_PASSWORD_ERROR']; 239 } 240 241 if ($data['email'] != $data['email_confirm']) 242 { 243 $error[] = $user->lang['NEW_EMAIL_ERROR']; 244 } 245 } 246 247 if (!sizeof($error)) 248 { 249 $server_url = generate_board_url(); 250 251 // Which group by default? 252 $group_name = ($coppa) ? 'REGISTERED_COPPA' : 'REGISTERED'; 253 254 $sql = 'SELECT group_id 255 FROM ' . GROUPS_TABLE . " 256 WHERE group_name = '" . $db->sql_escape($group_name) . "' 257 AND group_type = " . GROUP_SPECIAL; 258 $result = $db->sql_query($sql); 259 $row = $db->sql_fetchrow($result); 260 $db->sql_freeresult($result); 261 262 if (!$row) 263 { 264 trigger_error('NO_GROUP'); 265 } 266 267 $group_id = $row['group_id']; 268 269 if (($coppa || 270 $config['require_activation'] == USER_ACTIVATION_SELF || 271 $config['require_activation'] == USER_ACTIVATION_ADMIN) && $config['email_enable']) 272 { 273 $user_actkey = gen_rand_string(mt_rand(6, 10)); 274 $user_type = USER_INACTIVE; 275 $user_inactive_reason = INACTIVE_REGISTER; 276 $user_inactive_time = time(); 277 } 278 else 279 { 280 $user_type = USER_NORMAL; 281 $user_actkey = ''; 282 $user_inactive_reason = 0; 283 $user_inactive_time = 0; 284 } 285 286 $user_row = array( 287 'username' => $data['username'], 288 'user_password' => phpbb_hash($data['new_password']), 289 'user_email' => $data['email'], 290 'group_id' => (int) $group_id, 291 'user_timezone' => (float) $data['tz'], 292 'user_dst' => $is_dst, 293 'user_lang' => $data['lang'], 294 'user_type' => $user_type, 295 'user_actkey' => $user_actkey, 296 'user_ip' => $user->ip, 297 'user_regdate' => time(), 298 'user_inactive_reason' => $user_inactive_reason, 299 'user_inactive_time' => $user_inactive_time, 300 ); 301 302 if ($config['new_member_post_limit']) 303 { 304 $user_row['user_new'] = 1; 305 } 306 307 // Register user... 308 $user_id = user_add($user_row, $cp_data); 309 310 // This should not happen, because the required variables are listed above... 311 if ($user_id === false) 312 { 313 trigger_error('NO_USER', E_USER_ERROR); 314 } 315 316 // Okay, captcha, your job is done. 317 if ($config['enable_confirm'] && isset($captcha)) 318 { 319 $captcha->reset(); 320 } 321 322 if ($coppa && $config['email_enable']) 323 { 324 $message = $user->lang['ACCOUNT_COPPA']; 325 $email_template = 'coppa_welcome_inactive'; 326 } 327 else if ($config['require_activation'] == USER_ACTIVATION_SELF && $config['email_enable']) 328 { 329 $message = $user->lang['ACCOUNT_INACTIVE']; 330 $email_template = 'user_welcome_inactive'; 331 } 332 else if ($config['require_activation'] == USER_ACTIVATION_ADMIN && $config['email_enable']) 333 { 334 $message = $user->lang['ACCOUNT_INACTIVE_ADMIN']; 335 $email_template = 'admin_welcome_inactive'; 336 } 337 else 338 { 339 $message = $user->lang['ACCOUNT_ADDED']; 340 $email_template = 'user_welcome'; 341 } 342 343 if ($config['email_enable']) 344 { 345 include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); 346 347 $messenger = new messenger(false); 348 349 $messenger->template($email_template, $data['lang']); 350 351 $messenger->to($data['email'], $data['username']); 352 353 $messenger->anti_abuse_headers($config, $user); 354 355 $messenger->assign_vars(array( 356 'WELCOME_MSG' => htmlspecialchars_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename'])), 357 'USERNAME' => htmlspecialchars_decode($data['username']), 358 'PASSWORD' => htmlspecialchars_decode($data['new_password']), 359 'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u=$user_id&k=$user_actkey") 360 ); 361 362 if ($coppa) 363 { 364 $messenger->assign_vars(array( 365 'FAX_INFO' => $config['coppa_fax'], 366 'MAIL_INFO' => $config['coppa_mail'], 367 'EMAIL_ADDRESS' => $data['email']) 368 ); 369 } 370 371 $messenger->send(NOTIFY_EMAIL); 372 373 if ($config['require_activation'] == USER_ACTIVATION_ADMIN) 374 { 375 // Grab an array of user_id's with a_user permissions ... these users can activate a user 376 $admin_ary = $auth->acl_get_list(false, 'a_user', false); 377 $admin_ary = (!empty($admin_ary[0]['a_user'])) ? $admin_ary[0]['a_user'] : array(); 378 379 // Also include founders 380 $where_sql = ' WHERE user_type = ' . USER_FOUNDER; 381 382 if (sizeof($admin_ary)) 383 { 384 $where_sql .= ' OR ' . $db->sql_in_set('user_id', $admin_ary); 385 } 386 387 $sql = 'SELECT user_id, username, user_email, user_lang, user_jabber, user_notify_type 388 FROM ' . USERS_TABLE . ' ' . 389 $where_sql; 390 $result = $db->sql_query($sql); 391 392 while ($row = $db->sql_fetchrow($result)) 393 { 394 $messenger->template('admin_activate', $row['user_lang']); 395 $messenger->to($row['user_email'], $row['username']); 396 $messenger->im($row['user_jabber'], $row['username']); 397 398 $messenger->assign_vars(array( 399 'USERNAME' => htmlspecialchars_decode($data['username']), 400 'U_USER_DETAILS' => "$server_url/memberlist.$phpEx?mode=viewprofile&u=$user_id", 401 'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u=$user_id&k=$user_actkey") 402 ); 403 404 $messenger->send($row['user_notify_type']); 405 } 406 $db->sql_freeresult($result); 407 } 408 } 409 410 $message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>'); 411 trigger_error($message); 412 } 413 } 414 415 $s_hidden_fields = array( 416 'agreed' => 'true', 417 'change_lang' => 0, 418 ); 419 420 if ($config['coppa_enable']) 421 { 422 $s_hidden_fields['coppa'] = $coppa; 423 } 424 425 if ($config['enable_confirm']) 426 { 427 $s_hidden_fields = array_merge($s_hidden_fields, $captcha->get_hidden_fields()); 428 } 429 $s_hidden_fields = build_hidden_fields($s_hidden_fields); 430 $confirm_image = ''; 431 432 // Visual Confirmation - Show images 433 if ($config['enable_confirm']) 434 { 435 $template->assign_vars(array( 436 'CAPTCHA_TEMPLATE' => $captcha->get_template(), 437 )); 438 } 439 440 // 441 $l_reg_cond = ''; 442 switch ($config['require_activation']) 443 { 444 case USER_ACTIVATION_SELF: 445 $l_reg_cond = $user->lang['UCP_EMAIL_ACTIVATE']; 446 break; 447 448 case USER_ACTIVATION_ADMIN: 449 $l_reg_cond = $user->lang['UCP_ADMIN_ACTIVATE']; 450 break; 451 } 452 453 $template->assign_vars(array( 454 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '', 455 'USERNAME' => $data['username'], 456 'PASSWORD' => $data['new_password'], 457 'PASSWORD_CONFIRM' => $data['password_confirm'], 458 'EMAIL' => $data['email'], 459 'EMAIL_CONFIRM' => $data['email_confirm'], 460 461 'L_REG_COND' => $l_reg_cond, 462 'L_USERNAME_EXPLAIN' => sprintf($user->lang[$config['allow_name_chars'] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']), 463 'L_PASSWORD_EXPLAIN' => sprintf($user->lang[$config['pass_complex'] . '_EXPLAIN'], $config['min_pass_chars'], $config['max_pass_chars']), 464 465 'S_LANG_OPTIONS' => language_select($data['lang']), 466 'S_TZ_OPTIONS' => tz_select($data['tz']), 467 'S_CONFIRM_REFRESH' => ($config['enable_confirm'] && $config['confirm_refresh']) ? true : false, 468 'S_REGISTRATION' => true, 469 'S_COPPA' => $coppa, 470 'S_HIDDEN_FIELDS' => $s_hidden_fields, 471 'S_UCP_ACTION' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register'), 472 )); 473 474 // 475 $user->profile_fields = array(); 476 477 // Generate profile fields -> Template Block Variable profile_fields 478 $cp->generate_profile_fields('register', $user->get_iso_lang_id()); 479 480 // 481 $this->tpl_name = 'ucp_register'; 482 $this->page_title = 'UCP_REGISTRATION'; 483 } 484 } 485 486 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Oct 2 15:03:47 2013 | Cross-referenced by PHPXref 0.7.1 |