Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 48 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ucp_auth_link | |
0.00% |
0 / 46 |
|
0.00% |
0 / 1 |
182 | |
0.00% |
0 / 1 |
| main | |
0.00% |
0 / 46 |
|
0.00% |
0 / 1 |
182 | |||
| 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 | class ucp_auth_link |
| 23 | { |
| 24 | /** |
| 25 | * @var string |
| 26 | */ |
| 27 | public $u_action; |
| 28 | |
| 29 | /** |
| 30 | * Generates the ucp_auth_link page and handles the auth link process |
| 31 | * |
| 32 | * @param int $id |
| 33 | * @param string $mode |
| 34 | */ |
| 35 | public function main($id, $mode) |
| 36 | { |
| 37 | global $request, $template, $phpbb_container, $user; |
| 38 | |
| 39 | $error = array(); |
| 40 | |
| 41 | /* @var $provider_collection \phpbb\auth\provider_collection */ |
| 42 | $provider_collection = $phpbb_container->get('auth.provider_collection'); |
| 43 | $auth_provider = $provider_collection->get_provider(); |
| 44 | |
| 45 | // confirm that the auth provider supports this page |
| 46 | $provider_data = $auth_provider->get_auth_link_data(); |
| 47 | if ($provider_data === null) |
| 48 | { |
| 49 | $error[] = 'UCP_AUTH_LINK_NOT_SUPPORTED'; |
| 50 | } |
| 51 | |
| 52 | $s_hidden_fields = array(); |
| 53 | add_form_key('ucp_auth_link'); |
| 54 | |
| 55 | $submit = $request->variable('submit', false, false, \phpbb\request\request_interface::POST); |
| 56 | |
| 57 | // This path is only for primary actions |
| 58 | if (!count($error) && $submit) |
| 59 | { |
| 60 | if (!check_form_key('ucp_auth_link')) |
| 61 | { |
| 62 | $error[] = 'FORM_INVALID'; |
| 63 | } |
| 64 | |
| 65 | if (!count($error)) |
| 66 | { |
| 67 | // Any post data could be necessary for auth (un)linking |
| 68 | $link_data = $request->get_super_global(\phpbb\request\request_interface::POST); |
| 69 | |
| 70 | // The current user_id is also necessary |
| 71 | $link_data['user_id'] = $user->data['user_id']; |
| 72 | |
| 73 | // Tell the provider that the method is auth_link not login_link |
| 74 | $link_data['link_method'] = 'auth_link'; |
| 75 | |
| 76 | if ($request->variable('link', 0, false, \phpbb\request\request_interface::POST)) |
| 77 | { |
| 78 | $error[] = $auth_provider->link_account($link_data); |
| 79 | } |
| 80 | else |
| 81 | { |
| 82 | $error[] = $auth_provider->unlink_account($link_data); |
| 83 | } |
| 84 | |
| 85 | // Template data may have changed, get new data |
| 86 | $provider_data = $auth_provider->get_auth_link_data(); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | // In some cases, a request to an external server may be required. In |
| 91 | // these cases, the GET parameter 'link' should exist and should be true |
| 92 | if ($request->variable('link', false)) |
| 93 | { |
| 94 | // In this case the link data should only be populated with the |
| 95 | // link_method as the provider dictates how data is returned to it. |
| 96 | $link_data = array('link_method' => 'auth_link'); |
| 97 | |
| 98 | $error[] = $auth_provider->link_account($link_data); |
| 99 | |
| 100 | // Template data may have changed, get new data |
| 101 | $provider_data = $auth_provider->get_auth_link_data(); |
| 102 | } |
| 103 | |
| 104 | if (isset($provider_data['VARS'])) |
| 105 | { |
| 106 | // Handle hidden fields separately |
| 107 | if (isset($provider_data['VARS']['HIDDEN_FIELDS'])) |
| 108 | { |
| 109 | $s_hidden_fields = array_merge($s_hidden_fields, $provider_data['VARS']['HIDDEN_FIELDS']); |
| 110 | unset($provider_data['VARS']['HIDDEN_FIELDS']); |
| 111 | } |
| 112 | |
| 113 | $template->assign_vars($provider_data['VARS']); |
| 114 | } |
| 115 | |
| 116 | if (isset($provider_data['BLOCK_VAR_NAME'])) |
| 117 | { |
| 118 | foreach ($provider_data['BLOCK_VARS'] as $block_vars) |
| 119 | { |
| 120 | // See if there are additional hidden fields. This should be an associative array |
| 121 | if (isset($block_vars['HIDDEN_FIELDS'])) |
| 122 | { |
| 123 | $block_vars['HIDDEN_FIELDS'] = build_hidden_fields($block_vars['HIDDEN_FIELDS']); |
| 124 | } |
| 125 | |
| 126 | $template->assign_block_vars($provider_data['BLOCK_VAR_NAME'], $block_vars); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | $s_hidden_fields = build_hidden_fields($s_hidden_fields); |
| 131 | |
| 132 | // Replace "error" strings with their real, localised form |
| 133 | $error = array_map(array($user, 'lang'), $error); |
| 134 | $error = implode('<br />', $error); |
| 135 | |
| 136 | $template->assign_vars(array( |
| 137 | 'ERROR' => $error, |
| 138 | |
| 139 | 'PROVIDER_TEMPLATE_FILE' => $provider_data['TEMPLATE_FILE'], |
| 140 | |
| 141 | 'S_HIDDEN_FIELDS' => $s_hidden_fields, |
| 142 | 'S_UCP_ACTION' => $this->u_action, |
| 143 | )); |
| 144 | |
| 145 | $this->tpl_name = 'ucp_auth_link'; |
| 146 | $this->page_title = 'UCP_AUTH_LINK'; |
| 147 | } |
| 148 | } |