Skip to content

Commit

Permalink
Unique email domain allowed
Browse files Browse the repository at this point in the history
This PR add a restriction in case the user registration is needed, only
from a single mail domain.

##How to test
1. Go to the configs in the user manager
2. Fill the field "Unique mail domain", and save
3. Go to the frontend, and try to register with a different domain than
the field "Unique mail domain". A error message will show up, saying,
"Your mail domain xxx is not allowed".
  • Loading branch information
carlitorweb committed Apr 13, 2018
1 parent b5b9d49 commit 4e08bbf
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
7 changes: 7 additions & 0 deletions administrator/components/com_users/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
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="sendpassword"
type="radio"
Expand Down
2 changes: 2 additions & 0 deletions administrator/language/en-GB/en-GB.com_users.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ 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_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."
Expand Down
2 changes: 1 addition & 1 deletion components/com_users/controllers/registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function activate()
*
* @since 1.6
*/
public function register()
public function register()
{
// Check for request forgeries.
$this->checkToken();
Expand Down
10 changes: 10 additions & 0 deletions components/com_users/models/registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,16 @@ 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
$userMailDomain = explode('@',$data['email']);
if (!empty($allowedMailDomain) && $userMailDomain[1] != $allowedMailDomain)
{
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_USER_MAIL_DOMAIN_NOT_ALLOWED_MESSAGE', $userMailDomain[1]));

return false;
}

// Check if the user needs to activate their account.
if (($useractivation == 1) || ($useractivation == 2))
Expand Down
1 change: 1 addition & 0 deletions language/en-GB/en-GB.com_users.ini
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ COM_USERS_REGISTRATION_SAVE_FAILED="Registration failed: %s"
COM_USERS_REGISTRATION_SAVE_SUCCESS="Thank you for registering. You may now log in using the username and password you registered with."
COM_USERS_REGISTRATION_SEND_MAIL_FAILED="An error was encountered while sending the registration email. A message has been sent to the administrator of this site."
COM_USERS_REGISTRATION_VERIFY_SUCCESS="Your email address has been verified. Once an administrator approves your account you will be notified by email and you can login to the site."
COM_USERS_REGISTRATION_USER_MAIL_DOMAIN_NOT_ALLOWED_MESSAGE="Your mail domain <strong>%s</strong> is not allowed"
COM_USERS_REMIND="Reminder"
COM_USERS_REMIND_DEFAULT_LABEL="Please enter the email address associated with your User account. Your username will be emailed to the email address on file."
COM_USERS_REMIND_EMAIL_LABEL="Your Email"
Expand Down

0 comments on commit 4e08bbf

Please sign in to comment.