Auto enroll selected course, when user log in.

Auto enroll selected course, when user log in.

by Saddam Husain -
Number of replies: 2
Hi all community,


 I've such kind of situation here : I'm login into moodle via SSO(using moodle-auth_userkey) which is working well, now I want to auto enroll a selected course to logged in user and I'm using auto_enrol plugin for this, so there are two condition to enroll course which is.

 1. when user logged in : I follow with this one, but all courses (which has an instance of auto enroll) enrolled while I want a specific course to enroll.

 2. when loading the course : I followed this one as well with URL http://localhost/rs/course/view.php?id=14 but it shows me "This course is currently unavailable to students", so I showed this course from configuration(unhide) but I don't want to allow them to visible to users already.

Please help me, how can I achieve this.

Thanks.

Average of ratings: -
In reply to Saddam Husain

Re: Auto enroll selected course, when user log in.

by Saddam Husain -

Hello everyone,

I found solution for above situation, here I want to share it with you, so someone can get help from that.

First create session based on if `wantsurl` isn't empty in 'moodle/auth/userkey/auth.php' after line number 162 like.

if(!empty($wantsurl) && !empty($keyvalue)) {
$SESSION->SSO_enrol_session = "SSO_userkey_loggedIn";
}

Then modify code into `moodle/lib/moodlelib.php` on line number 2759 for check whether SSO_enrol_session not exist then execute 'notice()' otherwise not execute and finally unset the SSO session like.

if(!empty($wantsurl) && !empty($keyvalue)) {
$SESSION->SSO_enrol_session = "SSO_userkey_loggedIn";
}

Then after unset SSO session.

if(isset($SESSION->SSO_enrol_session)) {
unset($SESSION->SSO_enrol_session);
}


In reply to Saddam Husain

Re: Auto enroll selected course, when user log in.

by S G -
@saddam Husain


While I cannot help you with your query, I have used the auto-enroll plugin and found a serious issue.

I am not sure if it is exactly because of the auto_enroll plugin; but that was the only addition I made to my site before I ran into the issues below.

The enroll into course 'when course is opened' works fine; but the 'enroll on login' created issues for me.


All the users of my site (old and new) got enrolled into the courses where the auto_enroll plugin was used.

For some reason, the installation size started increasing rapidly and within one day, the Moodle installation size went from 5.5 GB to around 50 GB, which is the limit of my server space.

In less than 24 hours, the website crashed.


I had to reinstall everything from a older back-up. 


So, if you have enabled 'enroll on login' option, keep an eye on the installation size.