Friday, 06 October 2017 13:53

Joomla LDAP Plugin - Update email address

Rate this item
(0 votes)

I spent a little while searching for a way to update the Joomla user Email Address when the email address changes in Windows Active Directory. Of course, I'm using the LDAP plugin included in Joomla 3.x. The plugin can be found here. As you see, there isn't much documentation on it.

Since I couldn't find anything, I decided to edit the php file and make it work. Below is what I did.

Hope this helps someone.


1. Found the file in my Joomla site and opened it up for editing (ldap.php)

2. Went to line 150 or right after:

if (isset($userdetails[0][$ldap_email][0]))
{
$response->email = $userdetails[0][$ldap_email][0];

3. I Inserted the code:

// Grab email address, currently, in the Joomla User table
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('email')
->from('<<INSERT JOOMLA USER TABLE>>_users')
->where('username=' . "'{$credentials['username']}'");
$db->setQuery($query);
$result = $db->loadResult();

// Update Email address if it's different
$newemail = $userdetails[0][$ldap_email][0];
if ( $result == $newemail)
{
// echo "Same";
}
else
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->update('<<INSERT JOOMLA USER TABLE>>_users')
->set("email = '{$newemail}'")
->where('username=' . "'{$credentials['username']}'");
$db->setQuery($query);
$found = (int) $db->execute();

}

4. Done. Now, when the user logs in, it checks the email address to see if it's different. If it is, it updates it. If it's not, nothing happens.

Read 75 times Last modified on Friday, 06 October 2017 14:05

1 comment

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.