[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/includes/ucp/ -> ucp_register.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  /**
  15  * @ignore
  16  */
  17  if (!defined('IN_PHPBB'))
  18  {
  19      exit;
  20  }
  21  
  22  /**
  23  * ucp_register
  24  * Board registration
  25  */
  26  class ucp_register
  27  {
  28      var $u_action;
  29  
  30  	function main($id, $mode)
  31      {
  32          global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
  33          global $request, $phpbb_container, $phpbb_dispatcher;
  34  
  35          //
  36          if ($config['require_activation'] == USER_ACTIVATION_DISABLE ||
  37              (in_array($config['require_activation'], array(USER_ACTIVATION_SELF, USER_ACTIVATION_ADMIN)) && !$config['email_enable']))
  38          {
  39              trigger_error('UCP_REGISTER_DISABLE');
  40          }
  41  
  42          $coppa            = $request->is_set('coppa') ? (int) $request->variable('coppa', false) : false;
  43          $agreed            = $request->variable('agreed', false);
  44          $submit            = $request->is_set_post('submit');
  45          $change_lang    = request_var('change_lang', '');
  46          $user_lang        = request_var('lang', $user->lang_name);
  47  
  48          /**
  49          * Add UCP register data before they are assigned to the template or submitted
  50          *
  51          * To assign data to the template, use $template->assign_vars()
  52          *
  53          * @event core.ucp_register_requests_after
  54          * @var    bool    coppa        Is set coppa
  55          * @var    bool    agreed        Did user agree to coppa?
  56          * @var    bool    submit        Is set post submit?
  57          * @var    string    change_lang    Change language request
  58          * @var    string    user_lang    User language request
  59          * @since 3.1.11-RC1
  60          */
  61          $vars = array(
  62              'coppa',
  63              'agreed',
  64              'submit',
  65              'change_lang',
  66              'user_lang',
  67          );
  68          extract($phpbb_dispatcher->trigger_event('core.ucp_register_requests_after', compact($vars)));
  69  
  70          if ($agreed)
  71          {
  72              add_form_key('ucp_register');
  73          }
  74          else
  75          {
  76              add_form_key('ucp_register_terms');
  77          }
  78  
  79          if ($change_lang || $user_lang != $config['default_lang'])
  80          {
  81              $use_lang = ($change_lang) ? basename($change_lang) : basename($user_lang);
  82  
  83              if (!validate_language_iso_name($use_lang))
  84              {
  85                  if ($change_lang)
  86                  {
  87                      $submit = false;
  88  
  89                      // Setting back agreed to let the user view the agreement in his/her language
  90                      $agreed = false;
  91                  }
  92  
  93                  $user_lang = $use_lang;
  94              }
  95              else
  96              {
  97                  $change_lang = '';
  98                  $user_lang = $user->lang_name;
  99              }
 100          }
 101  
 102          $cp = $phpbb_container->get('profilefields.manager');
 103  
 104          $error = $cp_data = $cp_error = array();
 105          $s_hidden_fields = array();
 106  
 107          // Handle login_link data added to $_hidden_fields
 108          $login_link_data = $this->get_login_link_data_array();
 109  
 110          if (!empty($login_link_data))
 111          {
 112              // Confirm that we have all necessary data
 113              $provider_collection = $phpbb_container->get('auth.provider_collection');
 114              $auth_provider = $provider_collection->get_provider($request->variable('auth_provider', ''));
 115  
 116              $result = $auth_provider->login_link_has_necessary_data($login_link_data);
 117              if ($result !== null)
 118              {
 119                  $error[] = $user->lang[$result];
 120              }
 121  
 122              $s_hidden_fields = array_merge($s_hidden_fields, $this->get_login_link_data_for_hidden_fields($login_link_data));
 123          }
 124  
 125          if (!$agreed || ($coppa === false && $config['coppa_enable']) || ($coppa && !$config['coppa_enable']))
 126          {
 127              $add_coppa = ($coppa !== false) ? '&amp;coppa=' . $coppa : '';
 128  
 129              $s_hidden_fields = array_merge($s_hidden_fields, array(
 130                  'change_lang'    => '',
 131              ));
 132  
 133              // If we change the language, we want to pass on some more possible parameter.
 134              if ($change_lang)
 135              {
 136                  // We do not include the password
 137                  $s_hidden_fields = array_merge($s_hidden_fields, array(
 138                      'username'            => utf8_normalize_nfc(request_var('username', '', true)),
 139                      'email'                => strtolower(request_var('email', '')),
 140                      'lang'                => $user->lang_name,
 141                      'tz'                => request_var('tz', $config['board_timezone']),
 142                  ));
 143  
 144              }
 145  
 146              // Checking amount of available languages
 147              $sql = 'SELECT lang_id
 148                  FROM ' . LANG_TABLE;
 149              $result = $db->sql_query($sql);
 150  
 151              $lang_row = array();
 152              while ($row = $db->sql_fetchrow($result))
 153              {
 154                  $lang_row[] = $row;
 155              }
 156              $db->sql_freeresult($result);
 157  
 158              if ($coppa === false && $config['coppa_enable'])
 159              {
 160                  $now = getdate();
 161                  $coppa_birthday = $user->create_datetime()
 162                      ->setDate($now['year'] - 13, $now['mon'], $now['mday'] - 1)
 163                      ->setTime(0, 0, 0)
 164                      ->format($user->lang['DATE_FORMAT'], true);
 165                  unset($now);
 166  
 167                  $template->assign_vars(array(
 168                      'S_LANG_OPTIONS'    => (sizeof($lang_row) > 1) ? language_select($user_lang) : '',
 169                      'L_COPPA_NO'        => sprintf($user->lang['UCP_COPPA_BEFORE'], $coppa_birthday),
 170                      'L_COPPA_YES'        => sprintf($user->lang['UCP_COPPA_ON_AFTER'], $coppa_birthday),
 171  
 172                      'U_COPPA_NO'        => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register&amp;coppa=0'),
 173                      'U_COPPA_YES'        => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register&amp;coppa=1'),
 174  
 175                      'S_SHOW_COPPA'        => true,
 176                      'S_HIDDEN_FIELDS'    => build_hidden_fields($s_hidden_fields),
 177                      'S_UCP_ACTION'        => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register'),
 178  
 179                      'COOKIE_NAME'        => $config['cookie_name'],
 180                      'COOKIE_PATH'        => $config['cookie_path'],
 181                  ));
 182              }
 183              else
 184              {
 185                  $template->assign_vars(array(
 186                      'S_LANG_OPTIONS'    => (sizeof($lang_row) > 1) ? language_select($user_lang) : '',
 187                      'L_TERMS_OF_USE'    => sprintf($user->lang['TERMS_OF_USE_CONTENT'], $config['sitename'], generate_board_url()),
 188  
 189                      'S_SHOW_COPPA'        => false,
 190                      'S_REGISTRATION'    => true,
 191                      'S_HIDDEN_FIELDS'    => build_hidden_fields($s_hidden_fields),
 192                      'S_UCP_ACTION'        => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register' . $add_coppa),
 193  
 194                      'COOKIE_NAME'        => $config['cookie_name'],
 195                      'COOKIE_PATH'        => $config['cookie_path'],
 196                      )
 197                  );
 198              }
 199              unset($lang_row);
 200  
 201              /**
 202              * Allows to modify the agreements.
 203              *
 204              * To assign data to the template, use $template->assign_vars()
 205              *
 206              * @event core.ucp_register_agreement
 207              * @since 3.1.6-RC1
 208              */
 209              $phpbb_dispatcher->dispatch('core.ucp_register_agreement');
 210  
 211              $this->tpl_name = 'ucp_agreement';
 212              return;
 213          }
 214  
 215          // The CAPTCHA kicks in here. We can't help that the information gets lost on language change.
 216          if ($config['enable_confirm'])
 217          {
 218              $captcha = $phpbb_container->get('captcha.factory')->get_instance($config['captcha_plugin']);
 219              $captcha->init(CONFIRM_REG);
 220          }
 221  
 222          $timezone = $config['board_timezone'];
 223  
 224          $data = array(
 225              'username'            => utf8_normalize_nfc(request_var('username', '', true)),
 226              'new_password'        => $request->variable('new_password', '', true),
 227              'password_confirm'    => $request->variable('password_confirm', '', true),
 228              'email'                => strtolower(request_var('email', '')),
 229              'lang'                => basename(request_var('lang', $user->lang_name)),
 230              'tz'                => request_var('tz', $timezone),
 231          );
 232          /**
 233          * Add UCP register data before they are assigned to the template or submitted
 234          *
 235          * To assign data to the template, use $template->assign_vars()
 236          *
 237          * @event core.ucp_register_data_before
 238          * @var    bool    submit        Do we display the form only
 239          *                            or did the user press submit
 240          * @var    array    data        Array with current ucp registration data
 241          * @since 3.1.4-RC1
 242          */
 243          $vars = array('submit', 'data');
 244          extract($phpbb_dispatcher->trigger_event('core.ucp_register_data_before', compact($vars)));
 245  
 246          // Check and initialize some variables if needed
 247          if ($submit)
 248          {
 249              $error = validate_data($data, array(
 250                  'username'            => array(
 251                      array('string', false, $config['min_name_chars'], $config['max_name_chars']),
 252                      array('username', '')),
 253                  'new_password'        => array(
 254                      array('string', false, $config['min_pass_chars'], $config['max_pass_chars']),
 255                      array('password')),
 256                  'password_confirm'    => array('string', false, $config['min_pass_chars'], $config['max_pass_chars']),
 257                  'email'                => array(
 258                      array('string', false, 6, 60),
 259                      array('user_email')),
 260                  'tz'                => array('timezone'),
 261                  'lang'                => array('language_iso_name'),
 262              ));
 263  
 264              if (!check_form_key('ucp_register'))
 265              {
 266                  $error[] = $user->lang['FORM_INVALID'];
 267              }
 268  
 269              // Replace "error" strings with their real, localised form
 270              $error = array_map(array($user, 'lang'), $error);
 271  
 272              if ($config['enable_confirm'])
 273              {
 274                  $vc_response = $captcha->validate($data);
 275                  if ($vc_response !== false)
 276                  {
 277                      $error[] = $vc_response;
 278                  }
 279  
 280                  if ($config['max_reg_attempts'] && $captcha->get_attempt_count() > $config['max_reg_attempts'])
 281                  {
 282                      $error[] = $user->lang['TOO_MANY_REGISTERS'];
 283                  }
 284              }
 285  
 286              // DNSBL check
 287              if ($config['check_dnsbl'])
 288              {
 289                  if (($dnsbl = $user->check_dnsbl('register')) !== false)
 290                  {
 291                      $error[] = sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]);
 292                  }
 293              }
 294  
 295              // validate custom profile fields
 296              $cp->submit_cp_field('register', $user->get_iso_lang_id(), $cp_data, $error);
 297  
 298              if (!sizeof($error))
 299              {
 300                  if ($data['new_password'] != $data['password_confirm'])
 301                  {
 302                      $error[] = $user->lang['NEW_PASSWORD_ERROR'];
 303                  }
 304              }
 305              /**
 306              * Check UCP registration data after they are submitted
 307              *
 308              * @event core.ucp_register_data_after
 309              * @var    bool    submit        Do we display the form only
 310              *                            or did the user press submit
 311              * @var    array     data        Array with current ucp registration data
 312              * @var    array    cp_data        Array with custom profile fields data
 313              * @var    array     error        Array with list of errors
 314              * @since 3.1.4-RC1
 315              */
 316              $vars = array('submit', 'data', 'cp_data', 'error');
 317              extract($phpbb_dispatcher->trigger_event('core.ucp_register_data_after', compact($vars)));
 318  
 319              if (!sizeof($error))
 320              {
 321                  $server_url = generate_board_url();
 322  
 323                  // Which group by default?
 324                  $group_name = ($coppa) ? 'REGISTERED_COPPA' : 'REGISTERED';
 325  
 326                  $sql = 'SELECT group_id
 327                      FROM ' . GROUPS_TABLE . "
 328                      WHERE group_name = '" . $db->sql_escape($group_name) . "'
 329                          AND group_type = " . GROUP_SPECIAL;
 330                  $result = $db->sql_query($sql);
 331                  $row = $db->sql_fetchrow($result);
 332                  $db->sql_freeresult($result);
 333  
 334                  if (!$row)
 335                  {
 336                      trigger_error('NO_GROUP');
 337                  }
 338  
 339                  $group_id = $row['group_id'];
 340  
 341                  if (($coppa ||
 342                      $config['require_activation'] == USER_ACTIVATION_SELF ||
 343                      $config['require_activation'] == USER_ACTIVATION_ADMIN) && $config['email_enable'])
 344                  {
 345                      $user_actkey = gen_rand_string(mt_rand(6, 10));
 346                      $user_type = USER_INACTIVE;
 347                      $user_inactive_reason = INACTIVE_REGISTER;
 348                      $user_inactive_time = time();
 349                  }
 350                  else
 351                  {
 352                      $user_type = USER_NORMAL;
 353                      $user_actkey = '';
 354                      $user_inactive_reason = 0;
 355                      $user_inactive_time = 0;
 356                  }
 357  
 358                  // Instantiate passwords manager
 359                  $passwords_manager = $phpbb_container->get('passwords.manager');
 360  
 361                  $user_row = array(
 362                      'username'                => $data['username'],
 363                      'user_password'            => $passwords_manager->hash($data['new_password']),
 364                      'user_email'            => $data['email'],
 365                      'group_id'                => (int) $group_id,
 366                      'user_timezone'            => $data['tz'],
 367                      'user_lang'                => $data['lang'],
 368                      'user_type'                => $user_type,
 369                      'user_actkey'            => $user_actkey,
 370                      'user_ip'                => $user->ip,
 371                      'user_regdate'            => time(),
 372                      'user_inactive_reason'    => $user_inactive_reason,
 373                      'user_inactive_time'    => $user_inactive_time,
 374                  );
 375  
 376                  if ($config['new_member_post_limit'])
 377                  {
 378                      $user_row['user_new'] = 1;
 379                  }
 380                  /**
 381                  * Add into $user_row before user_add
 382                  *
 383                  * user_add allows adding more data into the users table
 384                  *
 385                  * @event core.ucp_register_user_row_after
 386                  * @var    bool    submit        Do we display the form only
 387                  *                            or did the user press submit
 388                  * @var    array    cp_data        Array with custom profile fields data
 389                  * @var    array    user_row    Array with current ucp registration data
 390                  * @since 3.1.4-RC1
 391                  */
 392                  $vars = array('submit', 'cp_data', 'user_row');
 393                  extract($phpbb_dispatcher->trigger_event('core.ucp_register_user_row_after', compact($vars)));
 394  
 395                  // Register user...
 396                  $user_id = user_add($user_row, $cp_data);
 397  
 398                  // This should not happen, because the required variables are listed above...
 399                  if ($user_id === false)
 400                  {
 401                      trigger_error('NO_USER', E_USER_ERROR);
 402                  }
 403  
 404                  // Okay, captcha, your job is done.
 405                  if ($config['enable_confirm'] && isset($captcha))
 406                  {
 407                      $captcha->reset();
 408                  }
 409  
 410                  if ($coppa && $config['email_enable'])
 411                  {
 412                      $message = $user->lang['ACCOUNT_COPPA'];
 413                      $email_template = 'coppa_welcome_inactive';
 414                  }
 415                  else if ($config['require_activation'] == USER_ACTIVATION_SELF && $config['email_enable'])
 416                  {
 417                      $message = $user->lang['ACCOUNT_INACTIVE'];
 418                      $email_template = 'user_welcome_inactive';
 419                  }
 420                  else if ($config['require_activation'] == USER_ACTIVATION_ADMIN && $config['email_enable'])
 421                  {
 422                      $message = $user->lang['ACCOUNT_INACTIVE_ADMIN'];
 423                      $email_template = 'admin_welcome_inactive';
 424                  }
 425                  else
 426                  {
 427                      $message = $user->lang['ACCOUNT_ADDED'];
 428                      $email_template = 'user_welcome';
 429                  }
 430  
 431                  if ($config['email_enable'])
 432                  {
 433                      include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
 434  
 435                      $messenger = new messenger(false);
 436  
 437                      $messenger->template($email_template, $data['lang']);
 438  
 439                      $messenger->to($data['email'], $data['username']);
 440  
 441                      $messenger->anti_abuse_headers($config, $user);
 442  
 443                      $messenger->assign_vars(array(
 444                          'WELCOME_MSG'    => htmlspecialchars_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename'])),
 445                          'USERNAME'        => htmlspecialchars_decode($data['username']),
 446                          'PASSWORD'        => htmlspecialchars_decode($data['new_password']),
 447                          'U_ACTIVATE'    => "$server_url/ucp.$phpEx?mode=activate&u=$user_id&k=$user_actkey")
 448                      );
 449  
 450                      if ($coppa)
 451                      {
 452                          $messenger->assign_vars(array(
 453                              'FAX_INFO'        => $config['coppa_fax'],
 454                              'MAIL_INFO'        => $config['coppa_mail'],
 455                              'EMAIL_ADDRESS'    => $data['email'])
 456                          );
 457                      }
 458  
 459                      $messenger->send(NOTIFY_EMAIL);
 460                  }
 461  
 462                  if ($config['require_activation'] == USER_ACTIVATION_ADMIN)
 463                  {
 464                      $phpbb_notifications = $phpbb_container->get('notification_manager');
 465                      $phpbb_notifications->add_notifications('notification.type.admin_activate_user', array(
 466                          'user_id'        => $user_id,
 467                          'user_actkey'    => $user_row['user_actkey'],
 468                          'user_regdate'    => $user_row['user_regdate'],
 469                      ));
 470                  }
 471  
 472                  // Perform account linking if necessary
 473                  if (!empty($login_link_data))
 474                  {
 475                      $login_link_data['user_id'] = $user_id;
 476  
 477                      $result = $auth_provider->link_account($login_link_data);
 478  
 479                      if ($result)
 480                      {
 481                          $message = $message . '<br /><br />' . $user->lang[$result];
 482                      }
 483                  }
 484  
 485                  $message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
 486                  trigger_error($message);
 487              }
 488          }
 489  
 490          $s_hidden_fields = array_merge($s_hidden_fields, array(
 491              'agreed'        => 'true',
 492              'change_lang'    => 0,
 493          ));
 494  
 495          if ($config['coppa_enable'])
 496          {
 497              $s_hidden_fields['coppa'] = $coppa;
 498          }
 499  
 500          if ($config['enable_confirm'])
 501          {
 502              $s_hidden_fields = array_merge($s_hidden_fields, $captcha->get_hidden_fields());
 503          }
 504          $s_hidden_fields = build_hidden_fields($s_hidden_fields);
 505          $confirm_image = '';
 506  
 507          // Visual Confirmation - Show images
 508          if ($config['enable_confirm'])
 509          {
 510              $template->assign_vars(array(
 511                  'CAPTCHA_TEMPLATE'        => $captcha->get_template(),
 512              ));
 513          }
 514  
 515          //
 516          $l_reg_cond = '';
 517          switch ($config['require_activation'])
 518          {
 519              case USER_ACTIVATION_SELF:
 520                  $l_reg_cond = $user->lang['UCP_EMAIL_ACTIVATE'];
 521              break;
 522  
 523              case USER_ACTIVATION_ADMIN:
 524                  $l_reg_cond = $user->lang['UCP_ADMIN_ACTIVATE'];
 525              break;
 526          }
 527  
 528          $timezone_selects = phpbb_timezone_select($template, $user, $data['tz'], true);
 529          $template->assign_vars(array(
 530              'ERROR'                => (sizeof($error)) ? implode('<br />', $error) : '',
 531              'USERNAME'            => $data['username'],
 532              'PASSWORD'            => $data['new_password'],
 533              'PASSWORD_CONFIRM'    => $data['password_confirm'],
 534              'EMAIL'                => $data['email'],
 535  
 536              'L_REG_COND'                => $l_reg_cond,
 537              'L_USERNAME_EXPLAIN'        => $user->lang($config['allow_name_chars'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_name_chars']), $user->lang('CHARACTERS', (int) $config['max_name_chars'])),
 538              'L_PASSWORD_EXPLAIN'        => $user->lang($config['pass_complex'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_pass_chars']), $user->lang('CHARACTERS', (int) $config['max_pass_chars'])),
 539  
 540              'S_LANG_OPTIONS'    => language_select($data['lang']),
 541              'S_TZ_PRESELECT'    => !$submit,
 542              'S_CONFIRM_REFRESH'    => ($config['enable_confirm'] && $config['confirm_refresh']) ? true : false,
 543              'S_REGISTRATION'    => true,
 544              'S_COPPA'            => $coppa,
 545              'S_HIDDEN_FIELDS'    => $s_hidden_fields,
 546              'S_UCP_ACTION'        => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register'),
 547  
 548              'COOKIE_NAME'        => $config['cookie_name'],
 549              'COOKIE_PATH'        => $config['cookie_path'],
 550          ));
 551  
 552          //
 553          $user->profile_fields = array();
 554  
 555          // Generate profile fields -> Template Block Variable profile_fields
 556          $cp->generate_profile_fields('register', $user->get_iso_lang_id());
 557  
 558          //
 559          $this->tpl_name = 'ucp_register';
 560          $this->page_title = 'UCP_REGISTRATION';
 561      }
 562  
 563      /**
 564      * Creates the login_link data array
 565      *
 566      * @return    array    Returns an array of all POST paramaters whose names
 567      *                    begin with 'login_link_'
 568      */
 569  	protected function get_login_link_data_array()
 570      {
 571          global $request;
 572  
 573          $var_names = $request->variable_names(\phpbb\request\request_interface::POST);
 574          $login_link_data = array();
 575          $string_start_length = strlen('login_link_');
 576  
 577          foreach ($var_names as $var_name)
 578          {
 579              if (strpos($var_name, 'login_link_') === 0)
 580              {
 581                  $key_name = substr($var_name, $string_start_length);
 582                  $login_link_data[$key_name] = $request->variable($var_name, '', false, \phpbb\request\request_interface::POST);
 583              }
 584          }
 585  
 586          return $login_link_data;
 587      }
 588  
 589      /**
 590      * Prepends they key names of an associative array with 'login_link_' for
 591      * inclusion on the page as hidden fields.
 592      *
 593      * @param    array    $data    The array to be modified
 594      * @return    array    The modified array
 595      */
 596  	protected function get_login_link_data_for_hidden_fields($data)
 597      {
 598          $new_data = array();
 599  
 600          foreach ($data as $key => $value)
 601          {
 602              $new_data['login_link_' . $key] = $value;
 603          }
 604  
 605          return $new_data;
 606      }
 607  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1