Browse files

MDL-23692 forgotpw: Move redirection logic to fn.

Moving to a function because the same logic will be needed in a new
place in later commits.
  • Loading branch information...
1 parent 4f3f652 commit f4491c2adee5efc819b2d9d4962249023ef549f5 @peterbulmer peterbulmer committed Jul 31, 2013
Showing with 33 additions and 25 deletions.
  1. +2 −25 login/index.php
  2. +31 −0 login/lib.php
View
27 login/index.php
@@ -25,6 +25,7 @@
*/
require('../config.php');
+require_once('lib.php');
// Try to prevent searching for sites that allow sign-up.
if (!isset($CFG->additionalhtmlhead)) {
@@ -193,31 +194,7 @@
set_moodle_cookie($USER->username);
}
- /// Prepare redirection
- if (user_not_fully_set_up($USER)) {
- $urltogo = $CFG->wwwroot.'/user/edit.php';
- // We don't delete $SESSION->wantsurl yet, so we get there later
-
- } else if (isset($SESSION->wantsurl) and (strpos($SESSION->wantsurl, $CFG->wwwroot) === 0 or strpos($SESSION->wantsurl, str_replace('http://', 'https://', $CFG->wwwroot)) === 0)) {
- $urltogo = $SESSION->wantsurl; /// Because it's an address in this site
- unset($SESSION->wantsurl);
-
- } else {
- // no wantsurl stored or external - go to homepage
- $urltogo = $CFG->wwwroot.'/';
- unset($SESSION->wantsurl);
- }
-
- // If the url to go to is the same as the site page, check for default homepage.
- if ($urltogo == ($CFG->wwwroot . '/')) {
- $home_page = get_home_page();
- // Go to my-moodle page instead of site homepage if defaulthomepage set to homepage_my
- if ($home_page == HOMEPAGE_MY && !is_siteadmin() && !isguestuser()) {
- if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot.'/' or $urltogo == $CFG->wwwroot.'/index.php') {
- $urltogo = $CFG->wwwroot.'/my/';
- }
- }
- }
+ $urltogo = get_postlogin_redirection();
/// check if user password has expired
/// Currently supported only for ldap-authentication module
View
31 login/lib.php
@@ -169,4 +169,35 @@ function forgotpw_process_pwset($token, $username) {
die; //never reached
}
+
+/* Determine where a user should be redirected after they have been logged in
+*/
+function get_postlogin_redirection() {
+ global $CFG, $SESSION, $USER;
+ /// Prepare redirection
+ if (user_not_fully_set_up($USER)) {
+ $urltogo = $CFG->wwwroot.'/user/edit.php';
+ // We don't delete $SESSION->wantsurl yet, so we get there later
+
+ } else if (isset($SESSION->wantsurl) and (strpos($SESSION->wantsurl, $CFG->wwwroot) === 0 or strpos($SESSION->wantsurl, str_replace('http://', 'https://', $CFG->wwwroot)) === 0)) {
+ $urltogo = $SESSION->wantsurl; /// Because it's an address in this site
+ unset($SESSION->wantsurl);
+ } else {
+ // no wantsurl stored or external - go to homepage
+ $urltogo = $CFG->wwwroot.'/';
+ unset($SESSION->wantsurl);
+ }
+
+ // If the url to go to is the same as the site page, check for default homepage.
+ if ($urltogo == ($CFG->wwwroot . '/')) {
+ $home_page = get_home_page();
+ // Go to my-moodle page instead of site homepage if defaulthomepage set to homepage_my
+ if ($home_page == HOMEPAGE_MY && !is_siteadmin() && !isguestuser()) {
+ if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot.'/' or $urltogo == $CFG->wwwroot.'/index.php') {
+ $urltogo = $CFG->wwwroot.'/my/';
+ }
+ }
+ }
+ return $urltogo;
+}
?>

0 comments on commit f4491c2

Please sign in to comment.