Moodle LDAP and Email Hack

Friday, October 1st, 2010

So 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)) {“.

Elgg LDAP Problem Solved…

Tuesday, March 4th, 2008

As I was experimenting with Elgg and LDAP, I realized that none of the users create via LDAP authentication would so up in browse until somebody added them as a friend. Of course adding somebody who doesn’t show up in the list is a bit difficult so it was sort of a deal breaker.

It turns out that the friends able is used someway in the browse feature and users that register themselves are automatically made friends with a “0″ user that doesn’t really exist. So basically, you have to add a little code to the /auth/LDAP/lib.php and then your LDAP created users will work wonderfully.

Basically, I slightly modified a post that I found on the Elgg forums.

1. Find line 153:

$user_id = insert_record(‘users’,$user);

2. Add the following below:

// adds “virtual” friend, so that user has at least one connection, and shows up in the browse feature.
$newid = user_info_username(‘ident’, $username);
$owner = 0;
$f = new StdClass;
$f->owner = $owner;
$f->friend = $newid;
$f->status = ‘perm’;

insert_record(‘friends’,$f);

The additionally code simple grabs the new users “ident” from the User table and inserts a friend record with the shadowy “0″ user.

Now, if I can just figure out how to setup the tag cloud to work correctly.