require_login for basic page with custom content

require_login for basic page with custom content

by Rick Mason -
Number of replies: 2

I have a basic page set up with custom content, and have added files to my custom theme set up to bring in the html that I need. I'd like to know if there is a way that I can require my user to login without having a course object attached.

I'm using Moodle 2.7


<?php

require_once('../../config.php');


$PAGE->set_context(get_system_context());

$PAGE->set_pagelayout('aod');

$PAGE->set_title("AOD: Analyst On Demand");

$PAGE->set_heading("AOD: Analyst On Demand");

$PAGE->set_url($CFG->wwwroot.'/tools/aod/test.php');

$content = "create some content";

echo $OUTPUT->header();

echo $content;

echo $OUTPUT->footer();



Average of ratings: Useful (1)
In reply to Rick Mason

Re: require_login for basic page with custom content

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Does just adding:

require_login();

(somewhere after $PAGE->set_url())

Not do what you are wanting?


Average of ratings: Useful (1)
In reply to Davo Smith

Re: require_login for basic page with custom content

by Rick Mason -

Thanks Davo,

That did the trick. My code

require_once('../../config.php');


$PAGE->set_context(get_system_context());

$PAGE->set_pagelayout('aod');

$PAGE->set_title("Your title");

$PAGE->set_heading("Blank page");

$PAGE->set_url($CFG->wwwroot.'/tools/aod/test.php');

require_login();


This forced the user to login and successfully redirected to the proper page