Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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_login_link.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 6.53 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_login_link
 024  * Allows users of external accounts link those accounts to their phpBB accounts
 025  * during an attempted login.
 026  */
 027  class ucp_login_link
 028  {
 029      /**
 030      * @var    string
 031      */
 032      public $u_action;
 033   
 034      /**
 035      * Generates the ucp_login_link page and handles login link process
 036      *
 037      * @param    int        $id
 038      * @param    string    $mode
 039      */
 040      function main($id, $mode)
 041      {
 042          global $config, $phpbb_container, $request, $template, $user;
 043          global $phpbb_root_path, $phpEx;
 044   
 045          // Initialize necessary variables
 046          $login_error = null;
 047          $login_link_error = null;
 048          $login_username = null;
 049   
 050          // Build the data array
 051          $data = $this->get_login_link_data_array();
 052   
 053          // Ensure the person was sent here with login_link data
 054          if (empty($data))
 055          {
 056              $login_link_error = $user->lang['LOGIN_LINK_NO_DATA_PROVIDED'];
 057          }
 058   
 059          // Use the auth_provider requested even if different from configured
 060          $auth_provider = 'auth.provider.' . $request->variable('auth_provider', $config['auth_method']);
 061          $auth_provider = $phpbb_container->get($auth_provider);
 062   
 063          // Set the link_method to login_link
 064          $data['link_method'] = 'login_link';
 065   
 066          // Have the authentication provider check that all necessary data is available
 067          $result = $auth_provider->login_link_has_necessary_data($data);
 068          if ($result !== null)
 069          {
 070              $login_link_error = $user->lang[$result];
 071          }
 072   
 073          // Perform link action if there is no error
 074          if (!$login_link_error)
 075          {
 076              if ($request->is_set_post('login'))
 077              {
 078                  $login_username = $request->variable('login_username', '', false, \phpbb\request\request_interface::POST);
 079                  $login_password = $request->untrimmed_variable('login_password', '', true, \phpbb\request\request_interface::POST);
 080   
 081                  $login_result = $auth_provider->login($login_username, $login_password);
 082   
 083                  // We only care if there is or is not an error
 084                  $login_error = $this->process_login_result($login_result);
 085   
 086                  if (!$login_error)
 087                  {
 088                      // Give the user_id to the data
 089                      $data['user_id'] = $login_result['user_row']['user_id'];
 090   
 091                      // The user is now logged in, attempt to link the user to the external account
 092                      $result = $auth_provider->link_account($data);
 093   
 094                      if ($result)
 095                      {
 096                          $login_link_error = $user->lang[$result];
 097                      }
 098                      else
 099                      {
 100                          // Finish login
 101                          $result = $user->session_create($login_result['user_row']['user_id'], false, false, true);
 102   
 103                          // Perform a redirect as the account has been linked
 104                          $this->perform_redirect();
 105                      }
 106                  }
 107              }
 108          }
 109   
 110          $template->assign_vars(array(
 111              // Common template elements
 112              'LOGIN_LINK_ERROR'        => $login_link_error,
 113              'PASSWORD_CREDENTIAL'    => 'login_password',
 114              'USERNAME_CREDENTIAL'    => 'login_username',
 115              'S_HIDDEN_FIELDS'        => $this->get_hidden_fields($data),
 116   
 117              // Registration elements
 118              'REGISTER_ACTION'    => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register'),
 119   
 120              // Login elements
 121              'LOGIN_ERROR'        => $login_error,
 122              'LOGIN_USERNAME'    => $login_username,
 123          ));
 124   
 125          $this->tpl_name = 'ucp_login_link';
 126          $this->page_title = 'UCP_LOGIN_LINK';
 127      }
 128   
 129      /**
 130      * Builds the hidden fields string from the data array.
 131      *
 132      * @param    array    $data    This function only includes data in the array
 133      *                            that has a key that begins with 'login_link_'
 134      * @return    string    A string of hidden fields that can be included in the
 135      *                    template
 136      */
 137      protected function get_hidden_fields($data)
 138      {
 139          $fields = array();
 140   
 141          foreach ($data as $key => $value)
 142          {
 143              $fields['login_link_' . $key] = $value;
 144          }
 145   
 146          return build_hidden_fields($fields);
 147      }
 148   
 149      /**
 150      * Builds the login_link data array
 151      *
 152      * @return    array    All login_link data. This is all GET data whose names
 153      *                    begin with 'login_link_'
 154      */
 155      protected function get_login_link_data_array()
 156      {
 157          global $request;
 158   
 159          $var_names = $request->variable_names(\phpbb\request\request_interface::GET);
 160          $login_link_data = array();
 161          $string_start_length = strlen('login_link_');
 162   
 163          foreach ($var_names as $var_name)
 164          {
 165              if (strpos($var_name, 'login_link_') === 0)
 166              {
 167                  $key_name = substr($var_name, $string_start_length);
 168                  $login_link_data[$key_name] = $request->variable($var_name, '', false, \phpbb\request\request_interface::GET);
 169              }
 170          }
 171   
 172          return $login_link_data;
 173      }
 174   
 175      /**
 176      * Processes the result array from the login process
 177      * @param    array    $result    The login result array
 178      * @return    string|null    If there was an error in the process, a string is
 179      *                        returned. If the login was successful, then null is
 180      *                        returned.
 181      */
 182      protected function process_login_result($result)
 183      {
 184          global $config, $request, $template, $user, $phpbb_container;
 185   
 186          $login_error = null;
 187   
 188          if ($result['status'] != LOGIN_SUCCESS)
 189          {
 190              // Handle all errors first
 191              if ($result['status'] == LOGIN_BREAK)
 192              {
 193                  trigger_error($result['error_msg']);
 194              }
 195   
 196              switch ($result['status'])
 197              {
 198                  case LOGIN_ERROR_ATTEMPTS:
 199   
 200                      $captcha = $phpbb_container->get('captcha.factory')->get_instance($config['captcha_plugin']);
 201                      $captcha->init(CONFIRM_LOGIN);
 202   
 203                      $template->assign_vars(array(
 204                          'CAPTCHA_TEMPLATE'            => $captcha->get_template(),
 205                      ));
 206   
 207                      $login_error = $user->lang[$result['error_msg']];
 208                  break;
 209   
 210                  case LOGIN_ERROR_PASSWORD_CONVERT:
 211                      $login_error = sprintf(
 212                          $user->lang[$result['error_msg']],
 213                          ($config['email_enable']) ? '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=sendpassword') . '">' : '',
 214                          ($config['email_enable']) ? '</a>' : '',
 215                          ($config['board_contact']) ? '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">' : '',
 216                          ($config['board_contact']) ? '</a>' : ''
 217                      );
 218                  break;
 219   
 220                  // Username, password, etc...
 221                  default:
 222                      $login_error = $user->lang[$result['error_msg']];
 223   
 224                      // Assign admin contact to some error messages
 225                      if ($result['error_msg'] == 'LOGIN_ERROR_USERNAME' || $result['error_msg'] == 'LOGIN_ERROR_PASSWORD')
 226                      {
 227                          $login_error = (!$config['board_contact']) ? sprintf($user->lang[$result['error_msg']], '', '') : sprintf($user->lang[$result['error_msg']], '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">', '</a>');
 228                      }
 229   
 230                  break;
 231              }
 232          }
 233   
 234          return $login_error;
 235      }
 236   
 237      /**
 238      * Performs a post login redirect
 239      */
 240      protected function perform_redirect()
 241      {
 242          global $phpbb_root_path, $phpEx;
 243          $url = append_sid($phpbb_root_path . 'index.' . $phpEx);
 244          redirect($url);
 245      }
 246  }
 247