Skip to content

Commit

Permalink
Work around for leftover user profile data after deleting a user record.
Browse files Browse the repository at this point in the history
Joomla leaves user profile data behind when you delete a user record. This confused the login plugin.
  • Loading branch information
Nicholas K. Dionysopoulos committed Aug 25, 2016
1 parent 01b8dcf commit 1cc71aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
30 changes: 0 additions & 30 deletions administrator/manifests/packages/pkg_weblinks.xml

This file was deleted.

22 changes: 20 additions & 2 deletions plugins/authentication/facebook/facebook.php
Expand Up @@ -132,7 +132,7 @@ public function onAjaxFacebook()
$userId = JUserHelper::getUserIdByEmail($fbUserEmail);
}

if ($userId == 0)
if (empty($userId))
{
$usersConfig = JComponentHelper::getParams('com_users');
$allowUserRegistration = $usersConfig->get('allowUserRegistration');
Expand Down Expand Up @@ -412,7 +412,25 @@ protected function getUserIdByFacebookId($fbUserId)
{
$id = $db->setQuery($query, 0, 1)->loadResult();

return empty($id) ? 0 : $id;
// Not found?
if (empty($id))
{
return 0;
}

/**
* If you delete a user its profile fields are left behind and confuse our code. Therefore we have to check
* if the user *really* exists. However we can't just go through JFactory::getUser() because if the user
* does not exist we'll end up with an ugly Warning on our page with a text similar to "JUser: :_load:
* Unable to load user with ID: 1234". This cannot be disabled so we have to be, um, a bit creative :/
*/
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('COUNT(*)')->from($db->qn('#__users'))
->where($db->qn('id') . ' = ' . $db->q($id));
$userExists = $db->setQuery($query)->loadResult();

return ($userExists == 0) ? 0 : $id;
}
catch (Exception $e)
{
Expand Down

0 comments on commit 1cc71aa

Please sign in to comment.