Skip to content

Commit

Permalink
MDL-53047 login: Fixed #anchor being lost after login process
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanheywood committed Mar 4, 2016
1 parent 7adc7ef commit e1d6edb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions login/index.php
Expand Up @@ -37,6 +37,7 @@

$testsession = optional_param('testsession', 0, PARAM_INT); // test session works properly
$cancel = optional_param('cancel', 0, PARAM_BOOL); // redirect to frontpage, needed for loginhttps
$anchor = optional_param('anchor', '', PARAM_RAW); // Used to restore hash anchor to wantsurl.

if ($cancel) {
redirect(new moodle_url('/'));
Expand Down Expand Up @@ -120,6 +121,15 @@
$frm = data_submitted();
}

// Restore the #anchor to the original wantsurl. Note that this
// will only work for internal auth plugins, SSO plugins such as
// SAML / CAS / OIDC will have to handle this correctly directly.
if ($anchor && isset($SESSION->wantsurl) && strpos($SESSION->wantsurl, '#') === false) {
$wantsurl = new moodle_url($SESSION->wantsurl);
$wantsurl->set_anchor(substr($anchor, 1));
$SESSION->wantsurl = $wantsurl->out();
}

/// Check if the user has actually submitted login data to us

if ($frm and isset($frm->username)) { // Login WITH cookies
Expand Down
2 changes: 2 additions & 0 deletions login/index_form.html
Expand Up @@ -53,6 +53,8 @@ <h2><?php print_string("login") ?></h2>
</div>
<?php } ?>
<div class="clearer"><!-- --></div>
<input id="anchor" type="hidden" name="anchor" value="" />
<script>document.getElementById('anchor').value = location.hash</script>
<input type="submit" id="loginbtn" value="<?php print_string("login") ?>" />
<div class="forgetpass"><a href="forgot_password.php"><?php print_string("forgotten") ?></a></div>
</form>
Expand Down

0 comments on commit e1d6edb

Please sign in to comment.