Skip to content

Conversation

fulldecent
Copy link
Contributor

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”

@Copilot Copilot AI review requested due to automatic review settings August 11, 2025 19:23
Copy link

netlify bot commented Aug 11, 2025

Deploy Preview for moodledevdocs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 532a820
🔍 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...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modifies the documentation for the require_login() function to clarify that its usage is optional rather than mandatory for all plugin scripts. The change addresses concerns about creating public pages in Moodle plugins that don't require user authentication.

  • Updates documentation language from prescriptive "should include" to conditional "if using"
  • Changes singular references to plural to include both require_login() and require_course_login()


This function does following:
These functions do the following:

- it verifies that user is logged in before accessing any course or activities (not-logged-in users can not enter any courses).
- user is logged in as gu
Copy link
Preview

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line appears to be incomplete or truncated. The sentence 'user is logged in as gu' doesn't provide clear information about what 'gu' represents or complete the thought.

Suggested change
- user is logged in as gu
- if the user is not enrolled, they may be logged in as a guest user (if allowed)

Copilot uses AI. Check for mistakes.

@fulldecent fulldecent removed their assignment Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant