Skip to content

Commit

Permalink
Option to select what restriction want use
Browse files Browse the repository at this point in the history
  • Loading branch information
carlitorweb committed May 4, 2018
1 parent 81f77af commit 3021bd2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 32 deletions.
30 changes: 17 additions & 13 deletions administrator/components/com_users/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,26 @@
checksuperusergroup="1"
/>

<field
name="whiteListMailDomain"
type="textarea"
label="COM_USERS_CONFIG_FIELD_WHITELIST_MAILDOMAIN_LABEL"
description="COM_USERS_CONFIG_FIELD_WHITELIST_MAILDOMAIN_DESC"
rows="7"
cols="3"
/>
<field
name="domainTLDRestriction"
type="list"
label="COM_USERS_CONFIG_FIELD_DOMAIN_TLD_RESTRICTION_LABEL"
description="COM_USERS_CONFIG_FIELD_DOMAIN_TLD_RESTRICTION_DESC"
default="0"
>
<option value="0">JNONE</option>
<option value="1">COM_USERS_CONFIG_FIELD_DOMAIN_TLD_RESTRICTION_OPTION_WHITELIST</option>
<option value="2">COM_USERS_CONFIG_FIELD_DOMAIN_TLD_RESTRICTION_OPTION_BLACKLIST</option>
</field>

<field
name="blackListMailDomain"
<field
name="listMailDomainTLD"
type="textarea"
label="COM_USERS_CONFIG_FIELD_BLACKLIST_MAILDOMAIN_LABEL"
description="COM_USERS_CONFIG_FIELD_BLACKLIST_MAILDOMAIN_DESC"
label="COM_USERS_CONFIG_FIELD_LIST_MAILDOMAIN_TLD_LABEL"
description="COM_USERS_CONFIG_FIELD_LIST_MAILDOMAIN_TLD_DESC"
rows="7"
cols="3"
cols="3"
showon="domainTLDRestriction:1,2"
/>

<field
Expand Down
41 changes: 26 additions & 15 deletions administrator/components/com_users/models/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,25 +216,36 @@ public function save($data)
$iAmSuperAdmin = $my->authorise('core.admin');

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

if ((!empty(array_filter($blackListMailDomain)) && !empty(array_intersect($needles, $blackListMailDomain)))
|| (!empty(array_filter($whiteListMailDomain)) && empty(array_intersect($needles, $whiteListMailDomain))))
if ($optionRestriction !== '0')
{
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_USER_MAIL_DOMAIN_NOT_ALLOWED_MESSAGE', $userMailDomain[1]));
$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_REGISTRATION_USER_MAIL_DOMAIN_NOT_ALLOWED_MESSAGE', $userMailDomain[1]));

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

return false;
}
}
}
// User cannot modify own user groups
if ((int) $user->id == (int) $my->id && !$iAmSuperAdmin && isset($data['groups']))
{
Expand Down
10 changes: 6 additions & 4 deletions administrator/language/en-GB/en-GB.com_users.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ COM_USERS_CATEGORIES_TITLE="User Notes: Categories"
COM_USERS_CATEGORY_HEADING="Category"
COM_USERS_CONFIG_FIELD_ALLOWREGISTRATION_DESC="If set to Yes, new Users are allowed to self-register."
COM_USERS_CONFIG_FIELD_ALLOWREGISTRATION_LABEL="Allow User Registration"
COM_USERS_CONFIG_FIELD_BLACKLIST_MAILDOMAIN_DESC="Users can register except those email domain and TLD (Top level domain) in the blacklist. Enter each domain or TLD in a new line. Example of a domain: gmail.com . Example of a TLD: gov"
COM_USERS_CONFIG_FIELD_BLACKLIST_MAILDOMAIN_LABEL="Blacklist Email/TLD"
COM_USERS_CONFIG_FIELD_CAPTCHA_DESC="Select the captcha plugin that will be used in the registration, password and username reminder forms. You may need to enter required information for your captcha plugin in the Plugin Manager.<br />If 'Use Global' is selected, make sure a captcha plugin is selected in Global Configuration."
COM_USERS_CONFIG_FIELD_CAPTCHA_LABEL="Captcha"
COM_USERS_CONFIG_FIELD_CHANGEUSERNAME_DESC="Allow users to change their Username when editing their profile."
COM_USERS_CONFIG_FIELD_CHANGEUSERNAME_LABEL="Change Username"
COM_USERS_CONFIG_FIELD_DOMAIN_TLD_RESTRICTION_DESC="Whitelist Email/TLD: Users can register only from the email domains and/or TLD (Top level domain) that are inside this list. Enter each domain or TLD in a new line. Example of a domain: gmail.com . Example of a TLD: gov\n\nBlacklist Email/TLD: Users can register except those email domain and TLD (Top level domain) in the blacklist. Enter each domain or TLD in a new line. Example of a domain: gmail.com . Example of a TLD: gov"
COM_USERS_CONFIG_FIELD_DOMAIN_TLD_RESTRICTION_LABEL="Email/TLD Restriction"
COM_USERS_CONFIG_FIELD_DOMAIN_TLD_RESTRICTION_OPTION_BLACKLIST="Blacklist"
COM_USERS_CONFIG_FIELD_DOMAIN_TLD_RESTRICTION_OPTION_WHITELIST="Whitelist"
COM_USERS_CONFIG_FIELD_FRONTEND_LANG_DESC="If 'Frontend User Parameters' is set to 'Show', users will be able to select their Frontend language preference when registering."
COM_USERS_CONFIG_FIELD_FRONTEND_LANG_LABEL="Frontend Language"
COM_USERS_CONFIG_FIELD_FRONTEND_RESET_COUNT_DESC="The maximum number of password resets allowed within the time period. Zero indicates no limit."
Expand All @@ -33,6 +35,8 @@ COM_USERS_CONFIG_FIELD_FRONTEND_USERPARAMS_DESC="If set to Show, Users will be a
COM_USERS_CONFIG_FIELD_FRONTEND_USERPARAMS_LABEL="Frontend User Parameters"
COM_USERS_CONFIG_FIELD_GUEST_USER_GROUP_DESC="The default Group that will be applied to Guest (not logged-in) Users."
COM_USERS_CONFIG_FIELD_GUEST_USER_GROUP_LABEL="Guest User Group"
COM_USERS_CONFIG_FIELD_LIST_MAILDOMAIN_TLD_DESC="List of emails domains and/or TLD"
COM_USERS_CONFIG_FIELD_LIST_MAILDOMAIN_TLD_LABEL="Email/TLD List"
COM_USERS_CONFIG_FIELD_MAILBODY_SUFFIX_DESC="This is added after the mail text."
COM_USERS_CONFIG_FIELD_MAILBODY_SUFFIX_LABEL="Mailbody Suffix"
COM_USERS_CONFIG_FIELD_MAILTOADMIN_DESC="If set to Yes then a notification mail will be sent to administrators if 'New User Account Activation' is set to 'None' or 'Self'."
Expand All @@ -56,8 +60,6 @@ COM_USERS_CONFIG_FIELD_USERACTIVATION_DESC="If set to None the user will be regi
COM_USERS_CONFIG_FIELD_USERACTIVATION_LABEL="New User Account Activation"
COM_USERS_CONFIG_FIELD_USERACTIVATION_OPTION_ADMINACTIVATION="Administrator"
COM_USERS_CONFIG_FIELD_USERACTIVATION_OPTION_SELFACTIVATION="Self"
COM_USERS_CONFIG_FIELD_WHITELIST_MAILDOMAIN_DESC="Users can register only from the email domains and/or TLD (Top level domain) that are inside this list. Enter each domain or TLD in a new line. Example of a domain: gmail.com . Example of a TLD: gov"
COM_USERS_CONFIG_FIELD_WHITELIST_MAILDOMAIN_LABEL="Whitelist Email/TLD"
COM_USERS_CONFIG_IMPORT_FAILED="An error was encountered while importing the configuration: %s."
COM_USERS_CONFIG_INTEGRATION_SETTINGS_DESC="These settings determine how the Users Component will integrate with other extensions."
COM_USERS_CONFIG_PASSWORD_OPTIONS="Password Options"
Expand Down

0 comments on commit 3021bd2

Please sign in to comment.