auto login to moodle from http url

Re: auto login to moodle from http url

by Nadav Kavalerchik -
Number of replies: 0
Picture of Core developers Picture of Plugin developers Picture of Testers Picture of Translators

Just had a similar request from our Teachers. (Auto login unregistered users into a Questionnaire)

Here is a YUI "AJAX" code I used inside a Label resource on the front page of the Course:

(replace the bold parts with your own values)

<p><button id="startme">Let me answer the questionnaire</button></p>

<script type="text/javascript">// <![CDATA[
Y.one('#startme').on('click',function(){

Y.io('http://YOUR-MOODLE/login/index.php',{
method:'POST',
data: {
username: 'guestuser',
password: 'guestpassword',
},
on:{
complete:function(id,response){
Y.one('#startme').setHTML('Connected');
Y.config.win.location = 'http://YOUR-MOODLE/mod/questionnaire/view.php?id=XXX';
},
start:function(id,response){
Y.one('#startme').setHTML('Logging in...');
}
}
});

});
// ]]></script>