From 6a85c048262c90c040dc801418e7a3ef65b7bb23 Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Sat, 27 Aug 2016 14:50:22 +1000 Subject: [PATCH] Fix #1 when redirecting to server root, not a moodle root --- auth.php | 6 +++--- tests/auth_plugin_test.php | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/auth.php b/auth.php index 09fcca0..6a24974 100644 --- a/auth.php +++ b/auth.php @@ -83,12 +83,12 @@ class auth_plugin_userkey extends auth_plugin_base { /** * Login user using userkey and return URL to redirect after. * - * @return mixed|string URL to redirect. + * @return string URL to redirect. * * @throws \moodle_exception If something went wrong. */ public function user_login_userkey() { - global $DB, $SESSION; + global $DB, $SESSION, $CFG; $keyvalue = required_param('key', PARAM_ALPHANUM); $wantsurl = optional_param('wantsurl', '', PARAM_URL); @@ -133,7 +133,7 @@ class auth_plugin_userkey extends auth_plugin_base { if (!empty($wantsurl)) { return $wantsurl; } else { - return '/'; + return $CFG->wwwroot; } } diff --git a/tests/auth_plugin_test.php b/tests/auth_plugin_test.php index 6335066..e71b42e 100644 --- a/tests/auth_plugin_test.php +++ b/tests/auth_plugin_test.php @@ -635,7 +635,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase { * Test that a user loggs in correctly. */ public function test_that_user_logged_in() { - global $DB, $USER, $SESSION; + global $DB, $USER, $SESSION, $CFG; $key = new stdClass(); $key->value = 'UserLogin'; @@ -651,8 +651,7 @@ class auth_plugin_userkey_testcase extends advanced_testcase { // Using @ is the only way to test this. Thanks moodle! $redirect = @$this->auth->user_login_userkey(); - - $this->assertEquals('/', $redirect); + $this->assertEquals($CFG->wwwroot, $redirect); $this->assertEquals($this->user->id, $USER->id); $this->assertSame(sesskey(), $USER->sesskey); $this->assertObjectHasAttribute('userkey', $SESSION);