Moodle
  1. Moodle
  2. MDL-37983

Default home page for users "user preference" ignored when $CFG->forcelogin is true

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.7, 2.3.4, 2.4.1, 2.5
    • Fix Version/s: 2.3.5, 2.4.2
    • Component/s: My home, Navigation
    • Labels:
    • Testing Instructions:
      Hide

      Notice

      • For this test you will need to make alterations to the database.

      Testing

      1. Log in as an admin.
      2. Set defaulthomepage to 'User preference' (Settings ► Site administration ► Appearance ► Navigation)
      3. Login as any user type e.g. 'student' and in the navigation browse to 'Home'.
      4. In settings expand My profile settings and check that there is a `Make this my default home page` link. (If not then go to My Home and check the same settings there).
      5. Do not Click this link. We want to leave the default home page to 'My Home'.
      6. Browse to any course.
        • Check that 'My home' is the first item in the navbar and that it links to /my/.
      7. Logout and then log back in.
        • Check that when logged in that you are redirected to 'My Home'.
      8. As the admin, go to [Settings ► Site administration ► Security ► Site policies] and set 'Force users to login' to yes (checked).
      9. As the student log out and log back in.
        • Check that when logged in that you are redirected to 'My Home'.
      10. Go into the database and alter the user fields. Remove the 'must be null' from the lastname field. Then delete the last name of the student that you are using to log in and out with.
      11. As the student, log out and log back in.
        • Check that you are redirected to the student edit page.
      12. Copy a url to redirect to such as http://your.moodle.site/course/view.php?id=3.
      13. As the student log out and then try to go straight to the above url.
        • Check that the student is redirected to the url location after logging in.
      14. The above steps should be re-done with the site page as the default home page.
      Show
      Notice For this test you will need to make alterations to the database. Testing Log in as an admin. Set defaulthomepage to 'User preference' (Settings ► Site administration ► Appearance ► Navigation) Login as any user type e.g. 'student' and in the navigation browse to 'Home'. In settings expand My profile settings and check that there is a `Make this my default home page` link. (If not then go to My Home and check the same settings there). Do not Click this link. We want to leave the default home page to 'My Home'. Browse to any course. Check that 'My home' is the first item in the navbar and that it links to /my/. Logout and then log back in. Check that when logged in that you are redirected to 'My Home'. As the admin, go to [Settings ► Site administration ► Security ► Site policies] and set 'Force users to login' to yes (checked). As the student log out and log back in. Check that when logged in that you are redirected to 'My Home'. Go into the database and alter the user fields. Remove the 'must be null' from the lastname field. Then delete the last name of the student that you are using to log in and out with. As the student, log out and log back in. Check that you are redirected to the student edit page. Copy a url to redirect to such as http://your.moodle.site/course/view.php?id=3 . As the student log out and then try to go straight to the above url. Check that the student is redirected to the url location after logging in. The above steps should be re-done with the site page as the default home page.
    • Affected Branches:
      MOODLE_22_STABLE, MOODLE_23_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE
    • Pull from Repository:
    • Pull 2.4 Branch:
      wip-MDL-37983-24
    • Pull Master Branch:
      wip-MDL-37983-master
    • Rank:
      47760

      Description

      Default home page 'user preference' has no effect on the first page displayed after logging in. The site home is always displayed regardless of which page a user has set as their default homepage.

      MDL-32108 was supposed to fix this, but it hasn't.

      This comment suggests the stanza be moved into the "else" clause above it. As a result, a fix that was working is now broken, and all users are sent to site home.

      If $SESSION->wantsurl === $CFG->wwwroot . '/' you end up in the "elseif" clause:

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

      because strpos($SESSION->wantsurl, $CFG->wwwroot) === 0 in that case. Something earlier in the sequence is setting $SESSION->wantsurl, possibly require_login() in moodlelib.php because we force login at our site.

      I think there are two possible fixes. Either detect the fact that $SESSION->wantsurl === $CFG->wwwroot . '/' in the "elseif" clause above, or move the whole homepage detecting code outside the if .. elseif .. else and place it in its own clause as below:

      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/';
              }
          }
      }
      

        Issue Links

          Activity

          Hide
          Rajesh Taneja added a comment -

          Adding Adrian, as watcher as he worked on MDL-32108

          Show
          Rajesh Taneja added a comment - Adding Adrian, as watcher as he worked on MDL-32108
          Hide
          Rajesh Taneja added a comment -

          Thanks for reporting this Chris,

          Adrian and I tried replicating this problem, but it seems it's working fine for us.

          Steps I followed:

          1. Logged in as admin
          2. Set defaulthomepage to 'User preference' (Settings > Site administration > Appearance > Navigation)
          3. Logged in as student clicked on "My Home"
          4. In settings expand My profile settings and check that there is a `Make this my default home page` link. (If not then go to Site Home and check the same settings there).
          5. Click Make this my default home page and log out
          6. Log in back and it takes me to My Home page.

          Please confirm if you are doing the same.

          Show
          Rajesh Taneja added a comment - Thanks for reporting this Chris, Adrian and I tried replicating this problem, but it seems it's working fine for us. Steps I followed: Logged in as admin Set defaulthomepage to 'User preference' (Settings > Site administration > Appearance > Navigation) Logged in as student clicked on "My Home" In settings expand My profile settings and check that there is a `Make this my default home page` link. (If not then go to Site Home and check the same settings there). Click Make this my default home page and log out Log in back and it takes me to My Home page. Please confirm if you are doing the same.
          Hide
          Chris Fryer added a comment -

          Thanks for your quick attention to this. I can reproduce the bug when "forcelogin" is true. You can set this by ticking "Force users to log in" in Site Administration -> Security -> Site Policies.

          Show
          Chris Fryer added a comment - Thanks for your quick attention to this. I can reproduce the bug when "forcelogin" is true. You can set this by ticking "Force users to log in" in Site Administration -> Security -> Site Policies.
          Hide
          Adrian Greeve added a comment -

          Thanks Chris for the clarification.

          I can confirm that this is the case. If you set forcelogin to true you will always be directed to the site page after logging in. After logging in, clicking home will redirect to the user preference.

          Show
          Adrian Greeve added a comment - Thanks Chris for the clarification. I can confirm that this is the case. If you set forcelogin to true you will always be directed to the site page after logging in. After logging in, clicking home will redirect to the user preference.
          Hide
          Rajesh Taneja added a comment -

          Thanks for more information on this, Chris.

          I've put that on the backlog and assigned to Adrian (As he worked on original solution.)

          Show
          Rajesh Taneja added a comment - Thanks for more information on this, Chris. I've put that on the backlog and assigned to Adrian (As he worked on original solution.)
          Hide
          Sam Hemelryk added a comment -

          Works perfectly thanks Adrian. Feel free to push up for assimilation when you are ready.

          Show
          Sam Hemelryk added a comment - Works perfectly thanks Adrian. Feel free to push up for assimilation when you are ready.
          Hide
          Adrian Greeve added a comment -

          Hooray!

          Thanks Sam for checking this for me.

          Sending for assimilation.

          Show
          Adrian Greeve added a comment - Hooray! Thanks Sam for checking this for me. Sending for assimilation.
          Hide
          Eloy Lafuente (stronk7) added a comment -

          The main moodle.git repository has just been updated with latest weekly modifications. You may wish to rebase your PULL branches to simplify history and avoid any possible merge conflicts. This would also make integrator's life easier next week.

          TIA and ciao

          Show
          Eloy Lafuente (stronk7) added a comment - The main moodle.git repository has just been updated with latest weekly modifications. You may wish to rebase your PULL branches to simplify history and avoid any possible merge conflicts. This would also make integrator's life easier next week. TIA and ciao
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Integrated (23, 24 & master), thanks!

          Show
          Eloy Lafuente (stronk7) added a comment - Integrated (23, 24 & master), thanks!
          Hide
          Frédéric Massart added a comment -

          Success! Thanks.

          Show
          Frédéric Massart added a comment - Success! Thanks.
          Hide
          Eloy Lafuente (stronk7) added a comment -

          This is valid for unlimited entries to the, soon to be unveiled, Moodle Codebase Gardens. It includes free access to all facilities.

          Personal and non-transferable to all assignees, reviewers and testers in this issue. Valid until switching to Blackboard (100000€ penalization will be applied).

          Thanks, closing as fixed!

          Show
          Eloy Lafuente (stronk7) added a comment - This is valid for unlimited entries to the, soon to be unveiled, Moodle Codebase Gardens. It includes free access to all facilities. Personal and non-transferable to all assignees, reviewers and testers in this issue. Valid until switching to Blackboard (100000€ penalization will be applied). Thanks, closing as fixed!

            People

            • Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: