mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[feature/oauth] More work on getting login link working
PHPBB3-11673
This commit is contained in:
parent
c09bda10fc
commit
ec160814b8
1 changed files with 81 additions and 63 deletions
|
@ -27,10 +27,7 @@ class ucp_login_link
|
|||
|
||||
function main($id, $mode)
|
||||
{
|
||||
global $auth, $config, $phpbb_container, $request, $template, $user;
|
||||
|
||||
$auth_provider = 'auth.provider.' . $request->variable('auth_provider', $config['auth_method']);
|
||||
$auth_provider = $phpbb_container->get($auth_provider);
|
||||
global $config, $phpbb_container, $request, $template, $user;
|
||||
|
||||
// Initialize necessary variables
|
||||
$login_error = null;
|
||||
|
@ -53,16 +50,82 @@ class ucp_login_link
|
|||
$login_link_error = $user->lang[$result];
|
||||
}
|
||||
|
||||
// Use the auth_provider requested even if different from configured
|
||||
$auth_provider = 'auth_provider.' . (array_key_exists('auth_provider', $data)) ? $data['auth_provider'] : $config['auth_method'];
|
||||
$auth_provider = $phpbb_container->get($auth_provider);
|
||||
|
||||
// Perform link action if there is no error
|
||||
if (!$login_link_error)
|
||||
{
|
||||
if ($request->is_set_post('login'))
|
||||
{
|
||||
// We only care if there is or is not an error
|
||||
$login_error = $this->perform_login_action();
|
||||
|
||||
if (!$login_error)
|
||||
{
|
||||
// The user is now logged in, attempt to link the user to the external account
|
||||
$result = $auth_provider->link_account($data);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$login_link_error = $user->lang[$result];
|
||||
} else {
|
||||
// Perform a redirect as the account has been linked
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$register_link = redirect('ucp.php?mode=register', true);
|
||||
|
||||
$template->assign_vars(array(
|
||||
// Common template elements
|
||||
'LOGIN_LINK_ERROR' => $login_link_error,
|
||||
'PASSWORD_CREDENTIAL' => 'login_password',
|
||||
'USERNAME_CREDENTIAL' => 'login_username',
|
||||
|
||||
// Registration elements
|
||||
'REGISTER_LINK' => $register_link,
|
||||
|
||||
// Login elements
|
||||
'LOGIN_ERROR' => $login_error,
|
||||
'LOGIN_USERNAME' => $login_username,
|
||||
));
|
||||
|
||||
$this->tpl_name = 'ucp_login_link';
|
||||
$this->page_title = 'UCP_LOGIN_LINK';
|
||||
}
|
||||
|
||||
protected function get_login_link_data_array()
|
||||
{
|
||||
global $request;
|
||||
|
||||
$var_names = $request->variable_names(phpbb_request_interface::GET);
|
||||
$login_link_data = array();
|
||||
|
||||
foreach ($var_names as $var_name)
|
||||
{
|
||||
if (strpos($var_name, 'login_link_') === 0)
|
||||
{
|
||||
$key_name = str_replace('login_link_', '', $var_name);
|
||||
$login_link_data[$key_name] = $request->variable($var_name, '', false, phpbb_request_interface::GET);
|
||||
}
|
||||
}
|
||||
|
||||
return $login_link_data;
|
||||
}
|
||||
|
||||
protected function perform_login_action()
|
||||
{
|
||||
global $auth, $config, $request, $template, $user;
|
||||
$login_username = $request->variable('login_username', '', false, phpbb_request_interface::POST);
|
||||
$login_password = $request->untrimmed_variable('password', '', true, phpbb_request_interface::POST);
|
||||
|
||||
$result = $auth->login($login_username, $login_password);
|
||||
|
||||
$login_error = null;
|
||||
|
||||
if ($result['status'] != LOGIN_SUCCESS)
|
||||
{
|
||||
// Handle all errors first
|
||||
|
@ -107,53 +170,8 @@ class ucp_login_link
|
|||
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// The user is now logged in, attempt to link the user to the external account
|
||||
$auth_provider->link_account($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Common template elements
|
||||
$template->assign_vars(array(
|
||||
'LOGIN_LINK_ERROR' => $login_link_error,
|
||||
'PASSWORD_CREDENTIAL' => 'login_password',
|
||||
'USERNAME_CREDENTIAL' => 'login_username',
|
||||
));
|
||||
|
||||
// Registration template
|
||||
$register_link = 'ucp.php?mode=register';
|
||||
|
||||
$template->assign_vars(array(
|
||||
'REGISTER_LINK' => redirect($register_link, true),
|
||||
));
|
||||
|
||||
// Link to existing account template
|
||||
$template->assign_vars(array(
|
||||
'LOGIN_ERROR' => $login_error,
|
||||
'LOGIN_USERNAME' => $login_username,
|
||||
));
|
||||
|
||||
$this->tpl_name = 'ucp_login_link';
|
||||
$this->page_title = 'UCP_LOGIN_LINK';
|
||||
}
|
||||
|
||||
protected function get_login_link_data_array()
|
||||
{
|
||||
global $request;
|
||||
|
||||
$var_names = $request->variable_names(phpbb_request_interface::GET);
|
||||
$login_link_data = array();
|
||||
|
||||
foreach ($var_names as $var_name)
|
||||
{
|
||||
if (strpos($var_name, 'login_link_') === 0)
|
||||
{
|
||||
$key_name = str_replace('login_link_', '', $var_name);
|
||||
$login_link_data[$key_name] = $request->variable($var_name, '', false, phpbb_request_interface::GET);
|
||||
}
|
||||
}
|
||||
|
||||
return $login_link_data;
|
||||
return $login_error;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue