Skip to content

Commit

Permalink
New option and code for com_admin.profile
Browse files Browse the repository at this point in the history
Fixed a miss check before see the whitelist
  • Loading branch information
carlitorweb committed May 4, 2018
1 parent 20bfc21 commit 51ecabe
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
42 changes: 27 additions & 15 deletions administrator/components/com_admin/models/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,34 @@ public function save($data)

// Check if the user mail domain or TLD is disallowed
$usersParams = JComponentHelper::getParams('com_users');
$whiteListMailDomain = explode("\r\n", $usersParams->get('whiteListMailDomain'));
$blackListMailDomain = explode("\r\n", $usersParams->get('blackListMailDomain'));
$userMailDomain = explode('@', $data['email']);
$getTLD = explode('.', $userMailDomain[1]);
$userMailTLD = array_pop($getTLD);
$needles = array(
'userMailDomain' => $userMailDomain[1],
'userMailTLD' => $userMailTLD,
);

if ((!empty(array_filter($blackListMailDomain)) && !empty(array_intersect($needles, $blackListMailDomain)))
|| (!empty(array_filter($whiteListMailDomain)) && empty(array_intersect($needles, $whiteListMailDomain))))
{
$this->setError(JText::sprintf('COM_USERS_MSG_USER_MAIL_DOMAIN_NOT_ALLOWED', $userMailDomain[1]));
$optionRestriction = $usersParams->get('domainTLDRestriction');

return false;
if ($optionRestriction !== '0')
{
$listMailDomainTLD = explode("\r\n", $usersParams->get('listMailDomainTLD'));
$userMailDomain = explode('@', $data['email']);
$getTLD = explode('.', $userMailDomain[1]);
$userMailTLD = array_pop($getTLD);
$needles = array(
'userMailDomain' => $userMailDomain[1],
'userMailTLD' => $userMailTLD,
);

if (!empty(array_filter($listMailDomainTLD)))
{
if ($optionRestriction === 2 && !empty(array_intersect($needles, $blackListMailDomain)))
{
$this->setError(JText::sprintf('COM_USERS_MSG_USER_MAIL_DOMAIN_NOT_ALLOWED', $userMailDomain[1]));

return false;
}
elseif ($optionRestriction === 1 && empty(array_intersect($needles, $whiteListMailDomain)))
{
$this->setError(JText::sprintf('COM_USERS_MSG_USER_MAIL_DOMAIN_NOT_ALLOWED', $userMailDomain[1]));

return false;
}
}
}

unset($data['id']);
Expand Down
2 changes: 1 addition & 1 deletion administrator/components/com_users/models/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public function save($data)

return false;
}
elseif (empty(array_intersect($needles, $whiteListMailDomain)))
elseif ($optionRestriction === 1 && empty(array_intersect($needles, $whiteListMailDomain)))
{
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_USER_MAIL_DOMAIN_NOT_ALLOWED_MESSAGE', $userMailDomain[1]));

Expand Down
2 changes: 1 addition & 1 deletion components/com_users/models/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public function save($data)

return false;
}
elseif (empty(array_intersect($needles, $whiteListMailDomain)))
elseif ($optionRestriction === 1 && empty(array_intersect($needles, $whiteListMailDomain)))
{
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_USER_MAIL_DOMAIN_NOT_ALLOWED_MESSAGE', $userMailDomain[1]));

Expand Down
2 changes: 1 addition & 1 deletion components/com_users/models/registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ public function register($temp)

return false;
}
elseif (empty(array_intersect($needles, $whiteListMailDomain)))
elseif ($optionRestriction === 1 && empty(array_intersect($needles, $whiteListMailDomain)))
{
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_USER_MAIL_DOMAIN_NOT_ALLOWED_MESSAGE', $userMailDomain[1]));

Expand Down

0 comments on commit 51ecabe

Please sign in to comment.