Advertisement
Guest User

ucp_register

a guest
Aug 30th, 2011
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.73 KB | None | 0 0
  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) ? '&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. 'minecraft_username' => request_var('minecraft_username', '', true),
  190. 'new_password' => request_var('new_password', '', true),
  191. 'password_confirm' => request_var('password_confirm', '', true),
  192. 'email' => strtolower(request_var('email', '')),
  193. 'email_confirm' => strtolower(request_var('email_confirm', '')),
  194. 'lang' => basename(request_var('lang', $user->lang_name)),
  195. 'tz' => request_var('tz', (float) $timezone),
  196. );
  197.  
  198. // Check and initialize some variables if needed
  199. if ($submit)
  200. {
  201. $error = validate_data($data, array(
  202. 'username' => array(
  203. array('string', false, $config['min_name_chars'], $config['max_name_chars']),
  204. array('username', '')),
  205. 'new_password' => array(
  206. array('string', false, $config['min_pass_chars'], $config['max_pass_chars']),
  207. array('password')),
  208. 'password_confirm' => array('string', false, $config['min_pass_chars'], $config['max_pass_chars']),
  209. 'email' => array(
  210. array('string', false, 6, 60),
  211. array('email')),
  212. 'email_confirm' => array('string', false, 6, 60),
  213. 'minecraft_username'=> array('string', true, 5, 255),
  214. 'tz' => array('num', false, -14, 14),
  215. 'lang' => array('language_iso_name'),
  216. ));
  217.  
  218. if (!check_form_key('ucp_register'))
  219. {
  220. $error[] = $user->lang['FORM_INVALID'];
  221. }
  222.  
  223. // Replace "error" strings with their real, localised form
  224. $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
  225.  
  226. if ($config['enable_confirm'])
  227. {
  228. $vc_response = $captcha->validate($data);
  229. if ($vc_response !== false)
  230. {
  231. $error[] = $vc_response;
  232. }
  233.  
  234. if ($config['max_reg_attempts'] && $captcha->get_attempt_count() > $config['max_reg_attempts'])
  235. {
  236. $error[] = $user->lang['TOO_MANY_REGISTERS'];
  237. }
  238. }
  239.  
  240. // DNSBL check
  241. if ($config['check_dnsbl'])
  242. {
  243. if (($dnsbl = $user->check_dnsbl('register')) !== false)
  244. {
  245. $error[] = sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]);
  246. }
  247. }
  248.  
  249. // validate custom profile fields
  250. $cp->submit_cp_field('register', $user->get_iso_lang_id(), $cp_data, $error);
  251.  
  252. if (!sizeof($error))
  253. {
  254. if ($data['new_password'] != $data['password_confirm'])
  255. {
  256. $error[] = $user->lang['NEW_PASSWORD_ERROR'];
  257. }
  258.  
  259. if ($data['email'] != $data['email_confirm'])
  260. {
  261. $error[] = $user->lang['NEW_EMAIL_ERROR'];
  262. }
  263. }
  264.  
  265. if (!sizeof($error))
  266. {
  267. $server_url = generate_board_url();
  268.  
  269. // Which group by default?
  270. $group_name = ($coppa) ? 'REGISTERED_COPPA' : 'REGISTERED';
  271.  
  272. $sql = 'SELECT group_id
  273. FROM ' . GROUPS_TABLE . "
  274. WHERE group_name = '" . $db->sql_escape($group_name) . "'
  275. AND group_type = " . GROUP_SPECIAL;
  276. $result = $db->sql_query($sql);
  277. $row = $db->sql_fetchrow($result);
  278. $db->sql_freeresult($result);
  279.  
  280. if (!$row)
  281. {
  282. trigger_error('NO_GROUP');
  283. }
  284.  
  285. $group_id = $row['group_id'];
  286.  
  287. if (($coppa ||
  288. $config['require_activation'] == USER_ACTIVATION_SELF ||
  289. $config['require_activation'] == USER_ACTIVATION_ADMIN) && $config['email_enable'])
  290. {
  291. $user_actkey = gen_rand_string(mt_rand(6, 10));
  292. $user_type = USER_INACTIVE;
  293. $user_inactive_reason = INACTIVE_REGISTER;
  294. $user_inactive_time = time();
  295. }
  296. else
  297. {
  298. $user_type = USER_NORMAL;
  299. $user_actkey = '';
  300. $user_inactive_reason = 0;
  301. $user_inactive_time = 0;
  302. }
  303.  
  304. $user_row = array(
  305. 'username' => $data['username'],
  306. 'minecraft_username' => $data['minecraft_username'],
  307. 'user_password' => phpbb_hash($data['new_password']),
  308. 'user_email' => $data['email'],
  309. 'group_id' => (int) $group_id,
  310. 'user_timezone' => (float) $data['tz'],
  311. 'user_dst' => $is_dst,
  312. 'user_lang' => $data['lang'],
  313. 'user_type' => $user_type,
  314. 'user_actkey' => $user_actkey,
  315. 'user_ip' => $user->ip,
  316. 'user_regdate' => time(),
  317. 'user_inactive_reason' => $user_inactive_reason,
  318. 'user_inactive_time' => $user_inactive_time,
  319. );
  320.  
  321. if ($config['new_member_post_limit'])
  322. {
  323. $user_row['user_new'] = 1;
  324. }
  325.  
  326. // Register user...
  327. $user_id = user_add($user_row, $cp_data);
  328.  
  329. // This should not happen, because the required variables are listed above...
  330. if ($user_id === false)
  331. {
  332. trigger_error('NO_USER', E_USER_ERROR);
  333. }
  334.  
  335. // Okay, captcha, your job is done.
  336. if ($config['enable_confirm'] && isset($captcha))
  337. {
  338. $captcha->reset();
  339. }
  340.  
  341. if ($coppa && $config['email_enable'])
  342. {
  343. $message = $user->lang['ACCOUNT_COPPA'];
  344. $email_template = 'coppa_welcome_inactive';
  345. }
  346. else if ($config['require_activation'] == USER_ACTIVATION_SELF && $config['email_enable'])
  347. {
  348. $message = $user->lang['ACCOUNT_INACTIVE'];
  349. $email_template = 'user_welcome_inactive';
  350. }
  351. else if ($config['require_activation'] == USER_ACTIVATION_ADMIN && $config['email_enable'])
  352. {
  353. $message = $user->lang['ACCOUNT_INACTIVE_ADMIN'];
  354. $email_template = 'admin_welcome_inactive';
  355. }
  356. else
  357. {
  358. $message = $user->lang['ACCOUNT_ADDED'];
  359. $email_template = 'user_welcome';
  360. }
  361.  
  362. if ($config['email_enable'])
  363. {
  364. include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  365.  
  366. $messenger = new messenger(false);
  367.  
  368. $messenger->template($email_template, $data['lang']);
  369.  
  370. $messenger->to($data['email'], $data['username']);
  371.  
  372. $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
  373. $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
  374. $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
  375. $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
  376.  
  377. $messenger->assign_vars(array(
  378. 'WELCOME_MSG' => htmlspecialchars_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename'])),
  379. 'USERNAME' => htmlspecialchars_decode($data['username']),
  380. 'PASSWORD' => htmlspecialchars_decode($data['new_password']),
  381. 'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u=$user_id&k=$user_actkey")
  382. );
  383.  
  384. if ($coppa)
  385. {
  386. $messenger->assign_vars(array(
  387. 'FAX_INFO' => $config['coppa_fax'],
  388. 'MAIL_INFO' => $config['coppa_mail'],
  389. 'EMAIL_ADDRESS' => $data['email'])
  390. );
  391. }
  392.  
  393. $messenger->send(NOTIFY_EMAIL);
  394.  
  395. if ($config['require_activation'] == USER_ACTIVATION_ADMIN)
  396. {
  397. // Grab an array of user_id's with a_user permissions ... these users can activate a user
  398. $admin_ary = $auth->acl_get_list(false, 'a_user', false);
  399. $admin_ary = (!empty($admin_ary[0]['a_user'])) ? $admin_ary[0]['a_user'] : array();
  400.  
  401. // Also include founders
  402. $where_sql = ' WHERE user_type = ' . USER_FOUNDER;
  403.  
  404. if (sizeof($admin_ary))
  405. {
  406. $where_sql .= ' OR ' . $db->sql_in_set('user_id', $admin_ary);
  407. }
  408.  
  409. $sql = 'SELECT user_id, username, user_email, user_lang, user_jabber, user_notify_type
  410. FROM ' . USERS_TABLE . ' ' .
  411. $where_sql;
  412. $result = $db->sql_query($sql);
  413.  
  414. while ($row = $db->sql_fetchrow($result))
  415. {
  416. $messenger->template('admin_activate', $row['user_lang']);
  417. $messenger->to($row['user_email'], $row['username']);
  418. $messenger->im($row['user_jabber'], $row['username']);
  419.  
  420. $messenger->assign_vars(array(
  421. 'USERNAME' => htmlspecialchars_decode($data['username']),
  422. 'U_USER_DETAILS' => "$server_url/memberlist.$phpEx?mode=viewprofile&u=$user_id",
  423. 'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u=$user_id&k=$user_actkey")
  424. );
  425.  
  426. $messenger->send($row['user_notify_type']);
  427. }
  428. $db->sql_freeresult($result);
  429. }
  430. }
  431.  
  432. $message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
  433. trigger_error($message);
  434. }
  435. }
  436.  
  437. $s_hidden_fields = array(
  438. 'agreed' => 'true',
  439. 'change_lang' => 0,
  440. );
  441.  
  442. if ($config['coppa_enable'])
  443. {
  444. $s_hidden_fields['coppa'] = $coppa;
  445. }
  446.  
  447. if ($config['enable_confirm'])
  448. {
  449. $s_hidden_fields = array_merge($s_hidden_fields, $captcha->get_hidden_fields());
  450. }
  451. $s_hidden_fields = build_hidden_fields($s_hidden_fields);
  452. $confirm_image = '';
  453.  
  454. // Visual Confirmation - Show images
  455. if ($config['enable_confirm'])
  456. {
  457. $template->assign_vars(array(
  458. 'CAPTCHA_TEMPLATE' => $captcha->get_template(),
  459. ));
  460. }
  461.  
  462. //
  463. $l_reg_cond = '';
  464. switch ($config['require_activation'])
  465. {
  466. case USER_ACTIVATION_SELF:
  467. $l_reg_cond = $user->lang['UCP_EMAIL_ACTIVATE'];
  468. break;
  469.  
  470. case USER_ACTIVATION_ADMIN:
  471. $l_reg_cond = $user->lang['UCP_ADMIN_ACTIVATE'];
  472. break;
  473. }
  474.  
  475. $template->assign_vars(array(
  476. 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
  477. 'USERNAME' => $data['username'],
  478. 'MINECRAFT_USERNAME'=> $data['minecraft_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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement