Skip to content

Commit

Permalink
Whitelist/Blacklist mail domain
Browse files Browse the repository at this point in the history
  • Loading branch information
carlitorweb committed Apr 13, 2018
1 parent 4e08bbf commit 2820b9b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
21 changes: 16 additions & 5 deletions administrator/components/com_users/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,22 @@
checksuperusergroup="1"
/>

<field
name="allowedMailDomain"
type="text"
label="COM_USERS_CONFIG_FIELD_ALLOWED_MAILDOMAIN_LABEL"
description="COM_USERS_CONFIG_FIELD_ALLOWED_MAILDOMAIN_DESC"
<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="blackListMailDomain"
type="textarea"
label="COM_USERS_CONFIG_FIELD_BLACKLIST_MAILDOMAIN_LABEL"
description="COM_USERS_CONFIG_FIELD_BLACKLIST_MAILDOMAIN_DESC"
rows="7"
cols="3"
/>

<field
Expand Down
6 changes: 4 additions & 2 deletions administrator/language/en-GB/en-GB.com_users.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ COM_USERS_BATCH_OPTIONS="Batch process the selected users"
COM_USERS_BATCH_SET="Set To Group"
COM_USERS_CATEGORIES_TITLE="User Notes: Categories"
COM_USERS_CATEGORY_HEADING="Category"
COM_USERS_CONFIG_FIELD_ALLOWED_MAILDOMAIN_DESC="Mail domain only allowed to register on the site. Example: gmail.com"
COM_USERS_CONFIG_FIELD_ALLOWED_MAILDOMAIN_LABEL="Unique mail domain"
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_LABEL="Blacklist mail domain"
COM_USERS_CONFIG_FIELD_BLACKLIST_MAILDOMAIN_DESC="Accept all mail domain except for those in the blacklist. Enter each domain in a new line. Example of a domain: gmail.com"
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."
Expand Down Expand Up @@ -56,6 +56,8 @@ 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_LABEL="Whitelist mail domain"
COM_USERS_CONFIG_FIELD_WHITELIST_MAILDOMAIN_DESC="Accept only the mail domains that are within this list. Enter each domain in a new line. Example of a domain: gmail.com"
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
9 changes: 5 additions & 4 deletions components/com_users/models/registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,12 @@ public function register($temp)
$data['password'] = $data['password1'];
$useractivation = $params->get('useractivation');
$sendpassword = $params->get('sendpassword', 1);
$allowedMailDomain = $params->get('allowedMailDomain');

// Check in case can only register under a single mail domain
$whiteListMailDomain = explode("\r\n", $params->get('whiteListMailDomain'));
$blackListMailDomain = explode("\r\n", $params->get('blackListMailDomain'));
$userMailDomain = explode('@',$data['email']);
if (!empty($allowedMailDomain) && $userMailDomain[1] != $allowedMailDomain)

// Check if the user mail domain is disallowed
if ((!empty($blackListMailDomain) && in_array($userMailDomain[1], $blackListMailDomain)) || (!empty($whiteListMailDomain) && !in_array($userMailDomain[1], $whiteListMailDomain)))
{
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_USER_MAIL_DOMAIN_NOT_ALLOWED_MESSAGE', $userMailDomain[1]));

Expand Down

0 comments on commit 2820b9b

Please sign in to comment.