Monday, June 10, 2013

Automatically logging in a demo role in moodle

My customer asked if we could automatically log our users into moodle in our demo account. My first reaction was no, and then why not use the native guest role and have the *demo courses avail. to the guest role.  I could set this up using native moodle permissions.  Native meaning no need for me to customize any code or role behavior.  We realized after a bit, that we wanted to use a more specific account, the demo account.

After a little experimentation and this moodle forum that make the good point that you can pretty painlessly pass the user and password credentials in a form, since the moodle login page is expecting a form POST, not a url GET.  I added this code, including a reference to my custom designed submit button, to the login portal page. Note: I removed the "<" opening achor tag so the code would post.

echo '
form action="/student/login/index.php" method="post" name="login">
    input type="hidden" name="username" value="demo" />
    input type="hidden" name="password" value="demo2013!" />
    button type="submit">
 
/button> 
/form>
';


After clicking the button, my users are automatically logged into the demo account, in the student role and can see our courses that we have enrolled the demo account into.

This is a nice and easy way to promote our demo courses.

No comments:

Post a Comment