aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2014-11-01 22:41:27 +0100
committerNils Adermann <naderman@naderman.de>2014-11-01 22:41:27 +0100
commitdde1c7424f84c61c8b6dfdf23594535183c9f2f5 (patch)
treeb8b1abaa08dc33f8d48260490c879f61bc5fd472
parentf3588c66ec22b71e779da1497a690802e1c6b51a (diff)
parent8aec6b58e087fa86c71baaccbeb07fe7a495aee5 (diff)
downloadforums-dde1c7424f84c61c8b6dfdf23594535183c9f2f5.tar
forums-dde1c7424f84c61c8b6dfdf23594535183c9f2f5.tar.gz
forums-dde1c7424f84c61c8b6dfdf23594535183c9f2f5.tar.bz2
forums-dde1c7424f84c61c8b6dfdf23594535183c9f2f5.tar.xz
forums-dde1c7424f84c61c8b6dfdf23594535183c9f2f5.zip
Merge pull request #3104 from marc1706/ticket/13248-alt
[ticket/13248] Login functions need to use provider collection for retrieving provider
-rw-r--r--phpBB/includes/ucp/ucp_auth_link.php5
-rw-r--r--phpBB/includes/ucp/ucp_login_link.php6
-rw-r--r--phpBB/includes/ucp/ucp_register.php4
-rw-r--r--phpBB/phpbb/auth/auth.php6
-rw-r--r--phpBB/phpbb/auth/provider_collection.php8
-rw-r--r--tests/functional/auth_test.php19
6 files changed, 35 insertions, 13 deletions
diff --git a/phpBB/includes/ucp/ucp_auth_link.php b/phpBB/includes/ucp/ucp_auth_link.php
index a595ce46c3..748f0fdec2 100644
--- a/phpBB/includes/ucp/ucp_auth_link.php
+++ b/phpBB/includes/ucp/ucp_auth_link.php
@@ -34,11 +34,12 @@ class ucp_auth_link
*/
public function main($id, $mode)
{
- global $config, $request, $template, $phpbb_container, $user;
+ global $request, $template, $phpbb_container, $user;
$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
$provider_data = $auth_provider->get_auth_link_data();
diff --git a/phpBB/includes/ucp/ucp_login_link.php b/phpBB/includes/ucp/ucp_login_link.php
index 5ca5df00f7..27d59c56b7 100644
--- a/phpBB/includes/ucp/ucp_login_link.php
+++ b/phpBB/includes/ucp/ucp_login_link.php
@@ -39,7 +39,7 @@ class ucp_login_link
*/
function main($id, $mode)
{
- global $config, $phpbb_container, $request, $template, $user;
+ global $phpbb_container, $request, $template, $user;
global $phpbb_root_path, $phpEx;
// Initialize necessary variables
@@ -57,8 +57,8 @@ class ucp_login_link
}
// Use the auth_provider requested even if different from configured
- $auth_provider = 'auth.provider.' . $request->variable('auth_provider', $config['auth_method']);
- $auth_provider = $phpbb_container->get($auth_provider);
+ $provider_collection = $phpbb_container->get('auth.provider_collection');
+ $auth_provider = $provider_collection->get_provider($request->variable('auth_provider', ''));
// Set the link_method to login_link
$data['link_method'] = 'login_link';
diff --git a/phpBB/includes/ucp/ucp_register.php b/phpBB/includes/ucp/ucp_register.php
index 9a15967bae..88078c10af 100644
--- a/phpBB/includes/ucp/ucp_register.php
+++ b/phpBB/includes/ucp/ucp_register.php
@@ -87,8 +87,8 @@ class ucp_register
if (!empty($login_link_data))
{
// Confirm that we have all necessary data
- $auth_provider = 'auth.provider.' . $request->variable('auth_provider', $config['auth_method']);
- $auth_provider = $phpbb_container->get($auth_provider);
+ $provider_collection = $phpbb_container->get('auth.provider_collection');
+ $auth_provider = $provider_collection->get_provider($request->variable('auth_provider', ''));
$result = $auth_provider->login_link_has_necessary_data($login_link_data);
if ($result !== null)
diff --git a/phpBB/phpbb/auth/auth.php b/phpBB/phpbb/auth/auth.php
index 38755ccf99..b59f0e60ec 100644
--- a/phpBB/phpbb/auth/auth.php
+++ b/phpBB/phpbb/auth/auth.php
@@ -927,11 +927,11 @@ class auth
*/
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)
{
$login = $provider->login($username, $password);
diff --git a/phpBB/phpbb/auth/provider_collection.php b/phpBB/phpbb/auth/provider_collection.php
index a74a2135dc..8e7e9e2cc1 100644
--- a/phpBB/phpbb/auth/provider_collection.php
+++ b/phpBB/phpbb/auth/provider_collection.php
@@ -38,6 +38,7 @@ class provider_collection extends \phpbb\di\service_collection
/**
* Get an auth provider.
*
+ * @param string $provider_name The name of the auth provider
* @return object Default auth provider selected in config if it
* does exist. Otherwise the standard db auth
* provider.
@@ -46,11 +47,12 @@ class provider_collection extends \phpbb\di\service_collection
* auth provider exist. The db auth provider
* 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
else if ($this->offsetExists('auth.provider.db'))
diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php
index b4b4279bf1..76e1709afb 100644
--- a/tests/functional/auth_test.php
+++ b/tests/functional/auth_test.php
@@ -34,6 +34,25 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
}
/**
+ * @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
*/
public function test_logout()