Automatic user creation and enrolement.

Automatic user creation and enrolement.

by Christopher Sangwin -
Number of replies: 10
Picture of Particularly helpful Moodlers Picture of Plugin developers
Hi there,

I'd like to create a script which will be called by another web application.

This script will be sent certain minimal information, e.g. username, authentication info etc via the $_POST method. From this it needs to

(1) check whether a user account exists, and if not
- create one automatically on the Moodle site.
- enrole the user on a specified subject within Moodle.

(2) log the user into Moodle and load the subject page direct.

To the user, they should hit one link in the external application and then end up (seemlessly) inside a Moodle course. Once inside Moodle they can update their user info as they see fit (except they can't change their username!)

Does such a script exist, and if not can anyone provide pointers about how to achieve this?

Of course, I'll post the script if we have to create it.

Thanks
Chris Sangwin
Average of ratings: -
In reply to Christopher Sangwin

Re: Automatic user creation and enrolement.

by Simon Hammond -
We found a script on another thread that is easily adapted to do just what we wanted.

We took the Blowfish authentication plugin from http://moodle.org/mod/forum/discuss.php?d=55669 and added the following hook for the redirect to auth.php:

function user_authenticated_hook(&$user, $username, $password) {
 global $CFG;
 $courses = array_keys(get_my_courses($user->id, 'id', 'id, visible'));
 $courseID = $courses[0]; // go for first one

 header("Location: ".$CFG->wwwroot."/course/view.php?id=".$courseID);
 exit();
}


Simon Hammond
In reply to Simon Hammond

Re: Automatic user creation and enrolement.

by Simon Hammond -
Actually, this additional hook only works for existing users and not for brand new ones.

Am still digging into how to redirect to the newly-enrolled course after authentication. Any pointers are very welcome.

Simon
In reply to Christopher Sangwin

Re: Automatic user creation and enrolement.

by Paul Kaiser -

Greetings Chris,

Here I am nearly 4 years in the future looking for EXACTLY the same functionality you described. My search continues, but since your question / needs match mine exactly, I wanted to ask if you found a solution?

Cheers,

Paul Kaiser

In reply to Paul Kaiser

Re: Automatic user creation and enrolement.

by Christopher Sangwin -
Picture of Particularly helpful Moodlers Picture of Plugin developers

Paul,

Yes, I did.  If you send me an email (c.j.sangwin@bham.ac.uk) then I'd be happy to share the code with you.

This is very low quality, and maybe insecure, so I'm holding off from posting it publically.  No explicit or implied warrenty here for any purpose......

In reply to Christopher Sangwin

Re: Automatic user creation and enrolement.

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

These days, the good way to do this seamless log-in from one learning system to another is to use LTI. Moodle can provide both ends of the connection:

  • It can play the part of an LTI consumer, let you log in to another system. You do that using the External tool activity, which comes as standard with Moodle.
  • Moodle can also be on the recieving end of a link from somewhere else if you install the LTI-provider add-on. See, for example, https://moodle.org/mod/forum/discuss.php?d=193355
In reply to Tim Hunt

Re: Automatic user creation and enrolement.

by Paul Kaiser -

Thanks Tim, this is great to know.

I'll have to check if my client's "portal" they are talking about can act as an LTI Consumer. They've mentioned "Liferay" and "Luminous" but I don't know much beyond that.

Great to know about LTI, and having a look at Chris' code for a general solution in case LTI Consumer isn't an option here.

Cheers,
Paul

In reply to Paul Kaiser

Re: Automatic user creation and enrolement.

by Peter Kowski -

Hi Paul. If you have any leads on how to use Liferay as an LTI consumer, I too would be very interested. I have been looking around for quite some time whether any LTI portlets exist for Liferay but not much luck I am afraid. sad

In reply to Christopher Sangwin

Re: Automatic user creation and enrolement.

by Qazi Hamayun -

Hi Chris

I am also searching for same code, can you send me the copy of your Code ?

In reply to Qazi Hamayun

Re: Automatic user creation and enrolement.

by Roger Mepham -

Hi Chris, I'm trying to do the same thing and would really appreciate a copy of your solution.

Thanks

Roger

In reply to Christopher Sangwin

Re: Automatic user creation and enrolement.

by Rekha C -

Hi Chris,

Email to your id returned undelivered.

I seek your help - please assist.

I have a moodle site eg. www.mymoodle.com, 2.9.3, and an ecommerce prestashop 1.6.1 eg.www.ecom.com where courses are purchased. Then, i want the presto.com user data (name, email id, mobile no.) to automatically create a moodle user, and enrol in the course purchased. 

Perhaps cron jobs are required to run every 1-3-5 min. How do education websites do instantaneous registration and enrolment?

Can APIs do this? Or by setting up an other external database which takes data from both sites?

I want to create new users and enroll into courses in moodle eg. www.mymoodle.com after registering & payment on  an ecommerce website eg. www.ecom.com.

Presently, after new users register & buy a course on www.ecom.com, i have to create a new user in moodle (one/bulk csv), and enroll them into courses they bought. This has a time delay, and a manual process.

External database authentication: seems does not create new users in www.mymoodle.com from external DB of www.ecom.com, and requires new user creation manually/csv and then matches user data fields with external DB in www.ecom.com.

External database enrolment: seems to enroll users into courses in www.mymoodle.com from external DB of www.ecom.com.