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)
|
function main($id, $mode)
|
||||||
{
|
{
|
||||||
global $auth, $config, $phpbb_container, $request, $template, $user;
|
global $config, $phpbb_container, $request, $template, $user;
|
||||||
|
|
||||||
$auth_provider = 'auth.provider.' . $request->variable('auth_provider', $config['auth_method']);
|
|
||||||
$auth_provider = $phpbb_container->get($auth_provider);
|
|
||||||
|
|
||||||
// Initialize necessary variables
|
// Initialize necessary variables
|
||||||
$login_error = null;
|
$login_error = null;
|
||||||
|
@ -53,83 +50,45 @@ class ucp_login_link
|
||||||
$login_link_error = $user->lang[$result];
|
$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
|
// Perform link action if there is no error
|
||||||
if (!$login_link_error)
|
if (!$login_link_error)
|
||||||
{
|
{
|
||||||
if ($request->is_set_post('login'))
|
if ($request->is_set_post('login'))
|
||||||
{
|
{
|
||||||
$login_username = $request->variable('login_username', '', false, phpbb_request_interface::POST);
|
// We only care if there is or is not an error
|
||||||
$login_password = $request->untrimmed_variable('password', '', true, phpbb_request_interface::POST);
|
$login_error = $this->perform_login_action();
|
||||||
|
|
||||||
$result = $auth->login($login_username, $login_password);
|
if (!$login_error)
|
||||||
|
|
||||||
if ($result['status'] != LOGIN_SUCCESS)
|
|
||||||
{
|
{
|
||||||
// Handle all errors first
|
|
||||||
if ($result['status'] == LOGIN_BREAK)
|
|
||||||
{
|
|
||||||
trigger_error($result['error_msg']);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($result['status'])
|
|
||||||
{
|
|
||||||
case LOGIN_ERROR_ATTEMPTS:
|
|
||||||
|
|
||||||
$captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
|
|
||||||
$captcha->init(CONFIRM_LOGIN);
|
|
||||||
|
|
||||||
$template->assign_vars(array(
|
|
||||||
'CAPTCHA_TEMPLATE' => $captcha->get_template(),
|
|
||||||
));
|
|
||||||
|
|
||||||
$login_error = $user->lang[$result['error_msg']];
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LOGIN_ERROR_PASSWORD_CONVERT:
|
|
||||||
$login_error = sprintf(
|
|
||||||
$user->lang[$result['error_msg']],
|
|
||||||
($config['email_enable']) ? '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=sendpassword') . '">' : '',
|
|
||||||
($config['email_enable']) ? '</a>' : '',
|
|
||||||
($config['board_contact']) ? '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">' : '',
|
|
||||||
($config['board_contact']) ? '</a>' : ''
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Username, password, etc...
|
|
||||||
default:
|
|
||||||
$login_error = $user->lang[$result['error_msg']];
|
|
||||||
|
|
||||||
// Assign admin contact to some error messages
|
|
||||||
if ($result['error_msg'] == 'LOGIN_ERROR_USERNAME' || $result['error_msg'] == 'LOGIN_ERROR_PASSWORD')
|
|
||||||
{
|
|
||||||
$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>');
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// The user is now logged in, attempt to link the user to the external account
|
// The user is now logged in, attempt to link the user to the external account
|
||||||
$auth_provider->link_account($data);
|
$result = $auth_provider->link_account($data);
|
||||||
|
|
||||||
|
if ($result)
|
||||||
|
{
|
||||||
|
$login_link_error = $user->lang[$result];
|
||||||
|
} else {
|
||||||
|
// Perform a redirect as the account has been linked
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Common template elements
|
$register_link = redirect('ucp.php?mode=register', true);
|
||||||
|
|
||||||
$template->assign_vars(array(
|
$template->assign_vars(array(
|
||||||
|
// Common template elements
|
||||||
'LOGIN_LINK_ERROR' => $login_link_error,
|
'LOGIN_LINK_ERROR' => $login_link_error,
|
||||||
'PASSWORD_CREDENTIAL' => 'login_password',
|
'PASSWORD_CREDENTIAL' => 'login_password',
|
||||||
'USERNAME_CREDENTIAL' => 'login_username',
|
'USERNAME_CREDENTIAL' => 'login_username',
|
||||||
));
|
|
||||||
|
|
||||||
// Registration template
|
// Registration elements
|
||||||
$register_link = 'ucp.php?mode=register';
|
'REGISTER_LINK' => $register_link,
|
||||||
|
|
||||||
$template->assign_vars(array(
|
// Login elements
|
||||||
'REGISTER_LINK' => redirect($register_link, true),
|
|
||||||
));
|
|
||||||
|
|
||||||
// Link to existing account template
|
|
||||||
$template->assign_vars(array(
|
|
||||||
'LOGIN_ERROR' => $login_error,
|
'LOGIN_ERROR' => $login_error,
|
||||||
'LOGIN_USERNAME' => $login_username,
|
'LOGIN_USERNAME' => $login_username,
|
||||||
));
|
));
|
||||||
|
@ -156,4 +115,63 @@ class ucp_login_link
|
||||||
|
|
||||||
return $login_link_data;
|
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
|
||||||
|
if ($result['status'] == LOGIN_BREAK)
|
||||||
|
{
|
||||||
|
trigger_error($result['error_msg']);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($result['status'])
|
||||||
|
{
|
||||||
|
case LOGIN_ERROR_ATTEMPTS:
|
||||||
|
|
||||||
|
$captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
|
||||||
|
$captcha->init(CONFIRM_LOGIN);
|
||||||
|
|
||||||
|
$template->assign_vars(array(
|
||||||
|
'CAPTCHA_TEMPLATE' => $captcha->get_template(),
|
||||||
|
));
|
||||||
|
|
||||||
|
$login_error = $user->lang[$result['error_msg']];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LOGIN_ERROR_PASSWORD_CONVERT:
|
||||||
|
$login_error = sprintf(
|
||||||
|
$user->lang[$result['error_msg']],
|
||||||
|
($config['email_enable']) ? '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=sendpassword') . '">' : '',
|
||||||
|
($config['email_enable']) ? '</a>' : '',
|
||||||
|
($config['board_contact']) ? '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">' : '',
|
||||||
|
($config['board_contact']) ? '</a>' : ''
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Username, password, etc...
|
||||||
|
default:
|
||||||
|
$login_error = $user->lang[$result['error_msg']];
|
||||||
|
|
||||||
|
// Assign admin contact to some error messages
|
||||||
|
if ($result['error_msg'] == 'LOGIN_ERROR_USERNAME' || $result['error_msg'] == 'LOGIN_ERROR_PASSWORD')
|
||||||
|
{
|
||||||
|
$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>');
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $login_error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue