Moodle LDAP and Email Hack
Friday, October 1st, 2010So all of our teachers have their email address in LDAP, but some students did not. This causes all sorts of problems when the student logs in the first time.
I realized that it would be easy enough to edit the file that creates new accounts to automatically insert an email address if the new email field is blank.
1. Navigate to <moodle_root>/lib/moodlelib.php
2. Edit the file by adding the logic below:
/**Removed (not) from line below and commented out text to automatically create a valid email address**/
if (empty($newuser->email)) {
/*if (email_is_not_allowed($newuser->email)) {
unset($newuser->email);
}*/
//This automatically creates email address based upon your domain.
$newuser->email = $username . "@your.domain";
}
3. Now when users login and don’t have email, they are automatically assigned an email. This same trick can be used if your students don’t have true email accounts.
I can’t remember which line you begin editing but you can find it by searching for “if (!empty($newuser->email)) {“.