Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ucp_register.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 18.05 KiB


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