[2.2] external db + auto logon from external LINK

[2.2] external db + auto logon from external LINK

by tim st.clair -
Number of replies: 0
Picture of Plugin developers

I have a situation where the users database is on another db on the same host. I can use external db authentication to solve this to a degree. Users sign up to an external portal and get granted access to stuff like courses on my moodle site (and other sites I don't care about). So they have an account and a bit of data that tells me which course they can access.

I can [in theory] put users into different cohorts and align courses to those cohorts so that as users go into a cohort, the course(s) appear for them in moodle. The page http://docs.moodle.org/22/en/External_database_enrolment mentions "The plugin will attempt to automatically enrol the student in all their courses according to the data in the external database" which sounds neat, but I can't work out how to configure that; if I go to my site and navigate to Home / Site administration / Plugins / Authentication / External database it doesn't show anything about courses.

What I need though is to automate their logon from an external link. We don't have a budget to do much programming at the external portal end and implementing oauth or saml is way out of budget (both in money and time). There is no ldap, active directory or whatever available, it's just a simple portal with a db. Users do not sign up or see a logon screen in Moodle, or change their profile in Moodle. It's just a course player, as such - so self enrolment and other external enrolment types are disabled (manual is still available).

I was thinking of something like this:

  • Portal opens a Moodle with a link like http://mysite.edu/moodle/local/login.php (e.g. a custom local plugin that I write to initiate the process)
  • It passes in (using GET) some querystring data like User=fredsmith01&Course=FS001&Verification=12345 (which would all be encrypted & verified of course, pretty easy so far)
  • Moodle would then use the EXTERNAL DB plugin to grab that user and log them in, creating the moodle user if need be at that time (e.g. NOT during some background process).
  • The user that is now created and has a session gets enrolled into a Cohort [which will exist] that was specified in the Course parameter that was sent in. I can add a Cohort Synch enrolment method to the course in Home / My courses / FS001 / Users / Enrolment methods
  • User is finally redirected back to the Moodle homepage so they can do whatever...
  • When the user logs off their moodle session would close and they get redirected back to the PORTAL site (not the MOODLE homepage). Likewise hitting their edit profile page - goes to the external Portal site. I think this possible.

So what I am asking is:

  • How do I correctly call "logon user" for a user that is in an external db from within my logon script? Logon is normally performed in /login/index.php; is there a way to call the same stuff from my own script? Or do I hack it to peices
  • How do I then take that user and then make them a member of the cohort (e.g. is there a function for doing this somewhere I can access through code?)
  • Am I going about this the wrong way?
Average of ratings: -