Fix #1 when redirecting to server root, not a moodle root

This commit is contained in:
Dmitrii Metelkin 2016-08-27 14:50:22 +10:00
parent f6bc25a61d
commit 6a85c04826
2 changed files with 5 additions and 6 deletions

View file

@ -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;
}
}

View file

@ -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);