Skip to content

Commit

Permalink
Merge pull request phpbb#3104 from marc1706/ticket/13248-alt
Browse files Browse the repository at this point in the history
[ticket/13248] Login functions need to use provider collection for retrieving provider
  • Loading branch information
naderman committed Nov 1, 2014
2 parents f3588c6 + 8aec6b5 commit dde1c74
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
5 changes: 3 additions & 2 deletions phpBB/includes/ucp/ucp_auth_link.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions phpBB/includes/ucp/ucp_login_link.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -57,8 +57,8 @@ function main($id, $mode)
}

// 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';
Expand Down
4 changes: 2 additions & 2 deletions phpBB/includes/ucp/ucp_register.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ function main($id, $mode)
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)
Expand Down
6 changes: 3 additions & 3 deletions phpBB/phpbb/auth/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -927,11 +927,11 @@ function _set_group_hold_ary(&$hold_ary, $option_id, $setting)
*/
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);
Expand Down
8 changes: 5 additions & 3 deletions phpBB/phpbb/auth/provider_collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function __construct(ContainerInterface $container, \phpbb\config\config
/**
* 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.
Expand All @@ -46,11 +47,12 @@ public function __construct(ContainerInterface $container, \phpbb\config\config
* 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'))
Expand Down
19 changes: 19 additions & 0 deletions tests/functional/auth_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ public function test_login_other()
$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
*/
Expand Down

0 comments on commit dde1c74

Please sign in to comment.