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 1112 times Last modified on Friday, 06 October 2017 14:05

3 comments

  • Comment Link joe Saturday, 07 October 2017 22:36 posted by joe

    great

    Report
  • Comment Link Diana Friday, 31 May 2019 20:57 posted by Diana

    Hello , excellent post. I need help. I am using Joomla 3.9.0 and until recently I had configured the Joomla authentication with LDAP, it turns out that recently 10 new users were incorporated to the domain and now my site does not authenticate these new users, but old users if you connect them. Any idea, I'm going crazy with this. regards

    Report
  • Comment Link Admin Monday, 03 June 2019 13:24 posted by Admin

    I had a problem like this a while back, but it turned out the infrastructure guys changed the server address so I only had to update the server name in Joomla. I would begin with testing the LDAP connection to see what changed. MS has a tool, ldp.exe, or you can look for ldapsearch. It seems to me something changed on the server side and these tools may be able to help you figure it out.
    Wish I had something more concrete....

    Report

Leave a comment

Because of spammers, I've changed the comments so they do not auto-show, but if you leave a comment, it should post within 24 hours.