aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Guse <nathaniel.guse@gmail.com>2014-03-12 18:48:41 -0500
committerNathan Guse <nathaniel.guse@gmail.com>2014-03-12 18:48:41 -0500
commitd69012ea6d65e938a72f7accca498fc9feb2df0d (patch)
treef18aa896ab7be6889f3860edc157cd8a3146cc6a
parentc6a87e77d4e11bd9e2e47e20c96fee66892c04b0 (diff)
parente07f3141179da9943ed51e754f15912dd24f4aff (diff)
downloadforums-d69012ea6d65e938a72f7accca498fc9feb2df0d.tar
forums-d69012ea6d65e938a72f7accca498fc9feb2df0d.tar.gz
forums-d69012ea6d65e938a72f7accca498fc9feb2df0d.tar.bz2
forums-d69012ea6d65e938a72f7accca498fc9feb2df0d.tar.xz
forums-d69012ea6d65e938a72f7accca498fc9feb2df0d.zip
Merge pull request #2104 from nickvergessen/ticket/12261
[ticket/12261] Remove web root path from login redirect url
-rw-r--r--phpBB/includes/functions.php10
-rw-r--r--tests/functional/extension_controller_test.php23
-rw-r--r--tests/functional/fixtures/ext/foo/bar/config/routing.yml4
-rw-r--r--tests/functional/fixtures/ext/foo/bar/config/services.yml1
-rw-r--r--tests/functional/fixtures/ext/foo/bar/controller/controller.php16
5 files changed, 50 insertions, 4 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 03cd235f86..5e5f508b6b 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -2344,7 +2344,7 @@ function reapply_sid($url)
*/
function build_url($strip_vars = false)
{
- global $user, $phpbb_root_path;
+ global $config, $user, $phpEx, $phpbb_root_path;
$page = $user->page['page'];
@@ -2357,6 +2357,12 @@ function build_url($strip_vars = false)
// URL
if ($url_parts === false || empty($url_parts['scheme']) || empty($url_parts['host']))
{
+ // Remove 'app.php/' from the page, when rewrite is enabled
+ if ($config['enable_mod_rewrite'] && strpos($page, 'app.' . $phpEx . '/') === 0)
+ {
+ $page = substr($page, strlen('app.' . $phpEx . '/'));
+ }
+
$page = $phpbb_root_path . $page;
}
@@ -4902,7 +4908,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0
'S_TOPIC_ID' => $topic_id,
'S_LOGIN_ACTION' => ((!defined('ADMIN_START')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login') : append_sid("{$phpbb_admin_path}index.$phpEx", false, true, $user->session_id)),
- 'S_LOGIN_REDIRECT' => build_hidden_fields(array('redirect' => build_url())),
+ 'S_LOGIN_REDIRECT' => build_hidden_fields(array('redirect' => $phpbb_path_helper->remove_web_root_path(build_url()))),
'S_ENABLE_FEEDS' => ($config['feed_enable']) ? true : false,
'S_ENABLE_FEEDS_OVERALL' => ($config['feed_overall']) ? true : false,
diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php
index 4725301141..57b0f56bee 100644
--- a/tests/functional/extension_controller_test.php
+++ b/tests/functional/extension_controller_test.php
@@ -113,11 +113,32 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
}
/**
+ * Check the redirect after using the login_box() form
+ */
+ public function test_login_redirect()
+ {
+ $this->markTestIncomplete('Session table contains incorrect data for controllers on travis,'
+ . 'therefor the redirect fails.');
+
+ $this->phpbb_extension_manager->enable('foo/bar');
+ $crawler = self::request('GET', 'app.php/foo/login_redirect');
+ $this->assertContainsLang('LOGIN', $crawler->filter('h2')->text());
+ $form = $crawler->selectButton('login')->form(array(
+ 'username' => 'admin',
+ 'password' => 'adminadmin',
+ ));
+ $this->assertStringStartsWith('./app.php/foo/login_redirect', $form->get('redirect')->getValue());
+
+ $crawler = self::submit($form);
+ $this->assertContains("I am a variable", $crawler->filter('#content')->text(), 'Unsuccessful redirect after using login_box()');
+ $this->phpbb_extension_manager->purge('foo/bar');
+ }
+
+ /**
* Check the output of a controller using the template system
*/
public function test_redirect()
{
- $filesystem = new \phpbb\filesystem();
$this->phpbb_extension_manager->enable('foo/bar');
$crawler = self::request('GET', 'app.php/foo/redirect');
diff --git a/tests/functional/fixtures/ext/foo/bar/config/routing.yml b/tests/functional/fixtures/ext/foo/bar/config/routing.yml
index d4d256c293..08bc73038f 100644
--- a/tests/functional/fixtures/ext/foo/bar/config/routing.yml
+++ b/tests/functional/fixtures/ext/foo/bar/config/routing.yml
@@ -14,6 +14,10 @@ foo_exception_controller:
pattern: /foo/exception
defaults: { _controller: foo_bar.controller:exception }
+foo_login_redirect_controller:
+ pattern: /foo/login_redirect
+ defaults: { _controller: foo_bar.controller:login_redirect }
+
foo_redirect_controller:
pattern: /foo/redirect
defaults: { _controller: foo_bar.controller:redirect }
diff --git a/tests/functional/fixtures/ext/foo/bar/config/services.yml b/tests/functional/fixtures/ext/foo/bar/config/services.yml
index cec69f7807..d35be7955a 100644
--- a/tests/functional/fixtures/ext/foo/bar/config/services.yml
+++ b/tests/functional/fixtures/ext/foo/bar/config/services.yml
@@ -6,6 +6,7 @@ services:
- @path_helper
- @template
- @config
+ - @user
- %core.root_path%
- %core.php_ext%
diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php
index 45246f8a97..47d856a5df 100644
--- a/tests/functional/fixtures/ext/foo/bar/controller/controller.php
+++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php
@@ -10,13 +10,15 @@ class controller
protected $helper;
protected $path_helper;
protected $config;
+ protected $user;
- public function __construct(\phpbb\controller\helper $helper, \phpbb\path_helper $path_helper, \phpbb\template\template $template, \phpbb\config\config $config, $root_path, $php_ext)
+ public function __construct(\phpbb\controller\helper $helper, \phpbb\path_helper $path_helper, \phpbb\template\template $template, \phpbb\config\config $config, \phpbb\user $user, $root_path, $php_ext)
{
$this->template = $template;
$this->helper = $helper;
$this->path_helper = $path_helper;
$this->config = $config;
+ $this->user = $user;
$this->root_path = $root_path;
$this->php_ext = $php_ext;
}
@@ -43,6 +45,18 @@ class controller
throw new \phpbb\controller\exception('Exception thrown from foo/exception route');
}
+ public function login_redirect()
+ {
+ if (!$this->user->data['is_registered'])
+ {
+ login_box();
+ }
+
+ $this->template->assign_var('A_VARIABLE', 'I am a variable');
+
+ return $this->helper->render('foo_bar_body.html');
+ }
+
public function redirect()
{
$url_root = generate_board_url();