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. |
|
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
ucp_login_link.php
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;
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 $template->assign_vars(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 $this->tpl_name = 'ucp_login_link';
127 $this->page_title = 'UCP_LOGIN_LINK';
128 }
129
130 /**
131 * Builds the hidden fields string from the data array.
132 *
133 * @param array $data This function only includes data in the array
134 * that has a key that begins with 'login_link_'
135 * @return string A string of hidden fields that can be included in the
136 * template
137 */
138 protected function get_hidden_fields($data)
139 {
140 $fields = array();
141
142 foreach ($data as $key => $value)
143 {
144 $fields['login_link_' . $key] = $value;
145 }
146
147 return build_hidden_fields($fields);
148 }
149
150 /**
151 * Builds the login_link data array
152 *
153 * @return array All login_link data. This is all GET data whose names
154 * begin with 'login_link_'
155 */
156 protected function get_login_link_data_array()
157 {
158 global $request;
159
160 $var_names = $request->variable_names(\phpbb\request\request_interface::GET);
161 $login_link_data = array();
162 $string_start_length = strlen('login_link_');
163
164 foreach ($var_names as $var_name)
165 {
166 if (strpos($var_name, 'login_link_') === 0)
167 {
168 $key_name = substr($var_name, $string_start_length);
169 $login_link_data[$key_name] = $request->variable($var_name, '', false, \phpbb\request\request_interface::GET);
170 }
171 }
172
173 return $login_link_data;
174 }
175
176 /**
177 * Processes the result array from the login process
178 * @param array $result The login result array
179 * @return string|null If there was an error in the process, a string is
180 * returned. If the login was successful, then null is
181 * returned.
182 */
183 protected function process_login_result($result)
184 {
185 global $config, $template, $user, $phpbb_container;
186
187 $login_error = null;
188
189 if ($result['status'] != LOGIN_SUCCESS)
190 {
191 // Handle all errors first
192 if ($result['status'] == LOGIN_BREAK)
193 {
194 trigger_error($result['error_msg']);
195 }
196
197 switch ($result['status'])
198 {
199 case LOGIN_ERROR_ATTEMPTS:
200
201 $captcha = $phpbb_container->get('captcha.factory')->get_instance($config['captcha_plugin']);
202 $captcha->init(CONFIRM_LOGIN);
203
204 $template->assign_vars(array(
205 'CAPTCHA_TEMPLATE' => $captcha->get_template(),
206 ));
207
208 $login_error = $user->lang[$result['error_msg']];
209 break;
210
211 case LOGIN_ERROR_PASSWORD_CONVERT:
212 $login_error = sprintf(
213 $user->lang[$result['error_msg']],
214 ($config['email_enable']) ? '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=sendpassword') . '">' : '',
215 ($config['email_enable']) ? '</a>' : '',
216 ($config['board_contact']) ? '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">' : '',
217 ($config['board_contact']) ? '</a>' : ''
218 );
219 break;
220
221 // Username, password, etc...
222 default:
223 $login_error = $user->lang[$result['error_msg']];
224
225 // Assign admin contact to some error messages
226 if ($result['error_msg'] == 'LOGIN_ERROR_USERNAME' || $result['error_msg'] == 'LOGIN_ERROR_PASSWORD')
227 {
228 $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>');
229 }
230
231 break;
232 }
233 }
234
235 return $login_error;
236 }
237
238 /**
239 * Performs a post login redirect
240 */
241 protected function perform_redirect()
242 {
243 global $phpbb_root_path, $phpEx;
244 $url = append_sid($phpbb_root_path . 'index.' . $phpEx);
245 redirect($url);
246 }
247 }
248