[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
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_login_link 24 * Allows users of external accounts link those accounts to their phpBB accounts 25 * during an attempted login. 26 */ 27 class ucp_login_link 28 { 29 /** 30 * @var string 31 */ 32 public $u_action; 33 34 /** 35 * Generates the ucp_login_link page and handles login link process 36 * 37 * @param int $id 38 * @param string $mode 39 */ 40 function main($id, $mode) 41 { 42 global $phpbb_container, $request, $template, $user; 43 global $phpbb_root_path, $phpEx; 44 45 // Initialize necessary variables 46 $login_error = null; 47 $login_link_error = null; 48 $login_username = null; 49 50 // Build the data array 51 $data = $this->get_login_link_data_array(); 52 53 // Ensure the person was sent here with login_link data 54 if (empty($data)) 55 { 56 $login_link_error = $user->lang['LOGIN_LINK_NO_DATA_PROVIDED']; 57 } 58 59 // Use the auth_provider requested even if different from configured 60 $provider_collection = $phpbb_container->get('auth.provider_collection'); 61 $auth_provider = $provider_collection->get_provider($request->variable('auth_provider', '')); 62 63 // Set the link_method to login_link 64 $data['link_method'] = 'login_link'; 65 66 // Have the authentication provider check that all necessary data is available 67 $result = $auth_provider->login_link_has_necessary_data($data); 68 if ($result !== null) 69 { 70 $login_link_error = $user->lang[$result]; 71 } 72 73 // Perform link action if there is no error 74 if (!$login_link_error) 75 { 76 if ($request->is_set_post('login')) 77 { 78 $login_username = $request->variable('login_username', '', true, \phpbb\request\request_interface::POST); 79 $login_password = $request->untrimmed_variable('login_password', '', true, \phpbb\request\request_interface::POST); 80 81 $login_result = $auth_provider->login($login_username, $login_password); 82 83 // We only care if there is or is not an error 84 $login_error = $this->process_login_result($login_result); 85 86 if (!$login_error) 87 { 88 // Give the user_id to the data 89 $data['user_id'] = $login_result['user_row']['user_id']; 90 91 // The user is now logged in, attempt to link the user to the external account 92 $result = $auth_provider->link_account($data); 93 94 if ($result) 95 { 96 $login_link_error = $user->lang[$result]; 97 } 98 else 99 { 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 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |