[docs] Allow pages to not use require_login
Need
I think it should be possible (and not violate recommendations) to create a Moodle plugin that has a public web page. No login. No access checks whatsoever. No dependency on turning on Guest User. No dependency on turning Guest User access to the course with id=1. No other dependencies whatsoever.
If you care, a specific use case is documented below (“USE CASE”), but that is not germane to the discussion. And please do not shut down this discussion if you disagree with that specific use case.
Problems
The documentation page for require_login(...) specifies that:
Each plugin script [on every non-internal page] should include require_login() or require_course_login() after setting up PAGE->url.
I disagree with this because of the reasons above.
Solution
I propose one of two alternative solutions:
a) Update that documentation to state the following:
If you wish to allow the page to successfully load when the visitor is not logged in (and do not redirect to ask them to login) then call it this way
require_login(..., ..., ...). There is no scenario in which this will stop the visitor from seeing the page.
-or-
b) Add a new function called do_not_require_login(...) which does what I am describing above in “a)” (which may or may not do logging and associate this page access with the course, if provided). And also update the “should include require_login() or require_course_login()" prescription with “or do_not_require_login(...)".
Use case
The imminent use case is that we have course completion certificates in Moodle. These certificates will have a QR code on them. And we are implementing that a visitor can scan these QR codes (on mobile) without logging in.
The people that are scanning/verifying these certificates care that the student has completed the course, and they do not care about logging in. And we do not care about them logging in.
Testing Instructions
The RequireLoginSniff, part of the Moodle Code Checker is now requiring the require_login() function on every page because of the documentation isssue above.
Automated test results
None
Pre-check results
None
Workaround
None
Other notes
This all-important require_login(...) function has some problems:
- Typos
- Grammatical errors
- Relies on an implicit understanding (i.e. not referenced) of how Guest User works and its configuration settings, and/or overrides/conflicts with other documentation on Guest Mode
- Not clear about whether it actually does or does not “require” “login”
Deploy Preview for moodledevdocs ready!
Built without sensitive environment variables
| Name | Link |
|---|---|
| Latest commit | 532a82008f0842cd781dab6ea71659aa7859d4ec |
| Latest deploy log | https://app.netlify.com/projects/moodledevdocs/deploys/689a434fc875190008cffcef |
| Deploy Preview | https://deploy-preview-1416--moodledevdocs.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify project configuration.