Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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: 02.04.2025, 15:02 - Dateigröße: 7.31 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 $phpbb_container, $request, $template, $user, $phpbb_dispatcher;
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          /* @var $provider_collection \phpbb\auth\provider_collection */
061          $provider_collection = $phpbb_container->get('auth.provider_collection');
062          $auth_provider = $provider_collection->get_provider($request->variable('auth_provider', ''));
063   
064          // Set the link_method to login_link
065          $data['link_method'] = 'login_link';
066   
067          // Have the authentication provider check that all necessary data is available
068          $result = $auth_provider->login_link_has_necessary_data($data);
069          if ($result !== null)
070          {
071              $login_link_error = $user->lang[$result];
072          }
073   
074          // Perform link action if there is no error
075          if (!$login_link_error)
076          {
077              if ($request->is_set_post('login'))
078              {
079                  $login_username = $request->variable('login_username', '', true, \phpbb\request\request_interface::POST);
080                  $login_password = $request->untrimmed_variable('login_password', '', true, \phpbb\request\request_interface::POST);
081   
082                  $login_result = $auth_provider->login($login_username, $login_password);
083   
084                  // We only care if there is or is not an error
085                  $login_error = $this->process_login_result($login_result);
086   
087                  if (!$login_error)
088                  {
089                      // Give the user_id to the data
090                      $data['user_id'] = $login_result['user_row']['user_id'];
091   
092                      // The user is now logged in, attempt to link the user to the external account
093                      $result = $auth_provider->link_account($data);
094   
095                      if ($result)
096                      {
097                          $login_link_error = $user->lang[$result];
098                      }
099                      else
100                      {
101                          // Finish login
102                          $user->session_create($login_result['user_row']['user_id'], false, false, true);
103   
104                          // Perform a redirect as the account has been linked
105                          $this->perform_redirect();
106                      }
107                  }
108              }
109          }
110   
111          $tpl_ary = array(
112              // Common template elements
113              'LOGIN_LINK_ERROR'        => $login_link_error,
114              'PASSWORD_CREDENTIAL'    => 'login_password',
115              'USERNAME_CREDENTIAL'    => 'login_username',
116              'S_HIDDEN_FIELDS'        => $this->get_hidden_fields($data),
117   
118              // Registration elements
119              'REGISTER_ACTION'    => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register'),
120   
121              // Login elements
122              'LOGIN_ERROR'        => $login_error,
123              'LOGIN_USERNAME'    => $login_username,
124          );
125   
126          /**
127          * Event to perform additional actions before ucp_login_link is displayed
128          *
129          * @event core.ucp_login_link_template_after
130          * @var    array                            data                Login link data
131          * @var    \phpbb\auth\provider_interface    auth_provider        Auth provider
132          * @var    string                            login_link_error    Login link error
133          * @var    string                            login_error            Login error
134          * @var    string                            login_username        Login username
135          * @var    array                            tpl_ary                Template variables
136          * @since 3.2.4-RC1
137          */
138          $vars = array('data', 'auth_provider', 'login_link_error', 'login_error', 'login_username', 'tpl_ary');
139          extract($phpbb_dispatcher->trigger_event('core.ucp_login_link_template_after', compact($vars)));
140   
141          $template->assign_vars($tpl_ary);
142   
143          $this->tpl_name = 'ucp_login_link';
144          $this->page_title = 'UCP_LOGIN_LINK';
145      }
146   
147      /**
148      * Builds the hidden fields string from the data array.
149      *
150      * @param    array    $data    This function only includes data in the array
151      *                            that has a key that begins with 'login_link_'
152      * @return    string    A string of hidden fields that can be included in the
153      *                    template
154      */
155      protected function get_hidden_fields($data)
156      {
157          $fields = array();
158   
159          foreach ($data as $key => $value)
160          {
161              $fields['login_link_' . $key] = $value;
162          }
163   
164          return build_hidden_fields($fields);
165      }
166   
167      /**
168      * Builds the login_link data array
169      *
170      * @return    array    All login_link data. This is all GET data whose names
171      *                    begin with 'login_link_'
172      */
173      protected function get_login_link_data_array()
174      {
175          global $request;
176   
177          $var_names = $request->variable_names(\phpbb\request\request_interface::GET);
178          $login_link_data = array();
179          $string_start_length = strlen('login_link_');
180   
181          foreach ($var_names as $var_name)
182          {
183              if (strpos($var_name, 'login_link_') === 0)
184              {
185                  $key_name = substr($var_name, $string_start_length);
186                  $login_link_data[$key_name] = $request->variable($var_name, '', false, \phpbb\request\request_interface::GET);
187              }
188          }
189   
190          return $login_link_data;
191      }
192   
193      /**
194      * Processes the result array from the login process
195      * @param    array    $result    The login result array
196      * @return    string|null    If there was an error in the process, a string is
197      *                        returned. If the login was successful, then null is
198      *                        returned.
199      */
200      protected function process_login_result($result)
201      {
202          global $config, $template, $user, $phpbb_container;
203   
204          $login_error = null;
205   
206          if ($result['status'] != LOGIN_SUCCESS)
207          {
208              // Handle all errors first
209              if ($result['status'] == LOGIN_BREAK)
210              {
211                  trigger_error($result['error_msg']);
212              }
213   
214              switch ($result['status'])
215              {
216                  case LOGIN_ERROR_ATTEMPTS:
217   
218                      $captcha = $phpbb_container->get('captcha.factory')->get_instance($config['captcha_plugin']);
219                      $captcha->init(CONFIRM_LOGIN);
220   
221                      $template->assign_vars(array(
222                          'CAPTCHA_TEMPLATE'            => $captcha->get_template(),
223                      ));
224   
225                      $login_error = $user->lang[$result['error_msg']];
226                  break;
227   
228                  case LOGIN_ERROR_PASSWORD_CONVERT:
229                      $login_error = sprintf(
230                          $user->lang[$result['error_msg']],
231                          ($config['email_enable']) ? '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=sendpassword') . '">' : '',
232                          ($config['email_enable']) ? '</a>' : '',
233                          ($config['board_contact']) ? '<a href="mailto:' . htmlspecialchars($config['board_contact'], ENT_COMPAT) . '">' : '',
234                          ($config['board_contact']) ? '</a>' : ''
235                      );
236                  break;
237   
238                  // Username, password, etc...
239                  default:
240                      $login_error = $user->lang[$result['error_msg']];
241   
242                      // Assign admin contact to some error messages
243                      if ($result['error_msg'] == 'LOGIN_ERROR_USERNAME' || $result['error_msg'] == 'LOGIN_ERROR_PASSWORD')
244                      {
245                          $login_error = (!$config['board_contact']) ? sprintf($user->lang[$result['error_msg']], '', '') : sprintf($user->lang[$result['error_msg']], '<a href="mailto:' . htmlspecialchars($config['board_contact'], ENT_COMPAT) . '">', '</a>');
246                      }
247   
248                  break;
249              }
250          }
251   
252          return $login_error;
253      }
254   
255      /**
256      * Performs a post login redirect
257      */
258      protected function perform_redirect()
259      {
260          global $phpbb_root_path, $phpEx;
261          $url = append_sid($phpbb_root_path . 'index.' . $phpEx);
262          redirect($url);
263      }
264  }
265