Merge pull request #3104 from marc1706/ticket/13248-alt

[ticket/13248] Login functions need to use provider collection for retrieving provider
This commit is contained in:
Nils Adermann 2014-11-01 22:41:27 +01:00
commit dde1c7424f
6 changed files with 35 additions and 13 deletions

View file

@ -34,11 +34,12 @@ class ucp_auth_link
*/ */
public function main($id, $mode) public function main($id, $mode)
{ {
global $config, $request, $template, $phpbb_container, $user; global $request, $template, $phpbb_container, $user;
$error = array(); $error = array();
$auth_provider = $phpbb_container->get('auth.provider.' . $config['auth_method']); $provider_collection = $phpbb_container->get('auth.provider_collection');
$auth_provider = $provider_collection->get_provider();
// confirm that the auth provider supports this page // confirm that the auth provider supports this page
$provider_data = $auth_provider->get_auth_link_data(); $provider_data = $auth_provider->get_auth_link_data();

View file

@ -39,7 +39,7 @@ class ucp_login_link
*/ */
function main($id, $mode) function main($id, $mode)
{ {
global $config, $phpbb_container, $request, $template, $user; global $phpbb_container, $request, $template, $user;
global $phpbb_root_path, $phpEx; global $phpbb_root_path, $phpEx;
// Initialize necessary variables // Initialize necessary variables
@ -57,8 +57,8 @@ class ucp_login_link
} }
// Use the auth_provider requested even if different from configured // Use the auth_provider requested even if different from configured
$auth_provider = 'auth.provider.' . $request->variable('auth_provider', $config['auth_method']); $provider_collection = $phpbb_container->get('auth.provider_collection');
$auth_provider = $phpbb_container->get($auth_provider); $auth_provider = $provider_collection->get_provider($request->variable('auth_provider', ''));
// Set the link_method to login_link // Set the link_method to login_link
$data['link_method'] = 'login_link'; $data['link_method'] = 'login_link';

View file

@ -87,8 +87,8 @@ class ucp_register
if (!empty($login_link_data)) if (!empty($login_link_data))
{ {
// Confirm that we have all necessary data // Confirm that we have all necessary data
$auth_provider = 'auth.provider.' . $request->variable('auth_provider', $config['auth_method']); $provider_collection = $phpbb_container->get('auth.provider_collection');
$auth_provider = $phpbb_container->get($auth_provider); $auth_provider = $provider_collection->get_provider($request->variable('auth_provider', ''));
$result = $auth_provider->login_link_has_necessary_data($login_link_data); $result = $auth_provider->login_link_has_necessary_data($login_link_data);
if ($result !== null) if ($result !== null)

View file

@ -927,11 +927,11 @@ class auth
*/ */
function login($username, $password, $autologin = false, $viewonline = 1, $admin = 0) function login($username, $password, $autologin = false, $viewonline = 1, $admin = 0)
{ {
global $config, $db, $user, $phpbb_root_path, $phpEx, $phpbb_container; global $db, $user, $phpbb_root_path, $phpEx, $phpbb_container;
$method = trim(basename($config['auth_method'])); $provider_collection = $phpbb_container->get('auth.provider_collection');
$provider = $phpbb_container->get('auth.provider.' . $method); $provider = $provider_collection->get_provider();
if ($provider) if ($provider)
{ {
$login = $provider->login($username, $password); $login = $provider->login($username, $password);

View file

@ -38,6 +38,7 @@ class provider_collection extends \phpbb\di\service_collection
/** /**
* Get an auth provider. * Get an auth provider.
* *
* @param string $provider_name The name of the auth provider
* @return object Default auth provider selected in config if it * @return object Default auth provider selected in config if it
* does exist. Otherwise the standard db auth * does exist. Otherwise the standard db auth
* provider. * provider.
@ -46,11 +47,12 @@ class provider_collection extends \phpbb\di\service_collection
* auth provider exist. The db auth provider * auth provider exist. The db auth provider
* should always exist in a phpBB installation. * should always exist in a phpBB installation.
*/ */
public function get_provider() public function get_provider($provider_name = '')
{ {
if ($this->offsetExists('auth.provider.' . basename(trim($this->config['auth_method'])))) $provider_name = ($provider_name !== '') ? $provider_name : basename(trim($this->config['auth_method']));
if ($this->offsetExists('auth.provider.' . $provider_name))
{ {
return $this->offsetGet('auth.provider.' . basename(trim($this->config['auth_method']))); return $this->offsetGet('auth.provider.' . $provider_name);
} }
// Revert to db auth provider if selected method does not exist // Revert to db auth provider if selected method does not exist
else if ($this->offsetExists('auth.provider.db')) else if ($this->offsetExists('auth.provider.db'))

View file

@ -33,6 +33,25 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
$this->assertContains('anothertestuser', $crawler->filter('#username_logged_in')->text()); $this->assertContains('anothertestuser', $crawler->filter('#username_logged_in')->text());
} }
/**
* @dependsOn test_login_other
*/
public function test_login_ucp_other_auth_provider()
{
global $cache, $config;
$cache = new phpbb_mock_null_cache;
$db = $this->get_db();
$sql = 'UPDATE ' . CONFIG_TABLE . " SET config_value = 'foobar' WHERE config_name = 'auth_method'";
$db->sql_query($sql);
$config['auth_method'] = 'foobar';
$this->login('anothertestuser');
$crawler = self::request('GET', 'index.php');
$this->assertContains('anothertestuser', $crawler->filter('#username_logged_in')->text());
$sql = 'UPDATE ' . CONFIG_TABLE . " SET config_value = 'db' WHERE config_name = 'auth_method'";
$db->sql_query($sql);
$config['auth_method'] = 'db';
}
/** /**
* @depends test_login * @depends test_login
*/ */