Skip to content

Commit

Permalink
removed depency on com_users
Browse files Browse the repository at this point in the history
bugfixes on regexpression
  • Loading branch information
mxkmp29 authored and mxkmp29 committed Aug 12, 2016
1 parent 669b592 commit 809f68a
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 36 deletions.
8 changes: 6 additions & 2 deletions administrator/components/com_users/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@
description="COM_USERS_CONFIG_FIELD_USERNAME_MINNUMCHARS_DESC"
first="0"
last="99"
step="1">
step="1"
default="0">
</field>

<field
Expand All @@ -206,7 +207,8 @@
description="COM_USERS_CONFIG_FIELD_USERNAME_MAXNUMCHARS_DESC"
first="0"
last="99"
step="1">
step="1"
default="0">
</field>

<field
Expand Down Expand Up @@ -252,6 +254,7 @@
cols="50"
filter="string"
showon="allowed_chars_username_preset:1,2,3"
default=""
>
</field>

Expand All @@ -263,6 +266,7 @@
rows="4"
cols="50"
filter="string"
default=""
>
</field>
</fieldset>
Expand Down
1 change: 1 addition & 0 deletions components/com_users/models/forms/registration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
required="true"
size="30"
validate="username"
component="com_users"
/>

<field
Expand Down
12 changes: 0 additions & 12 deletions language/en-GB/en-GB.com_users.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@
COM_USERS_ACTIVATION_TOKEN_NOT_FOUND="Verification code not found."
COM_USERS_CAPTCHA_LABEL="Captcha"
COM_USERS_CAPTCHA_DESC="Please complete the security check."
COM_USERS_CONFIG_FIELD_USERNAME_ALPHANUMERIC_REQUIRED="Only alphanumeric characters for username field are allowed."
COM_USERS_CONFIG_FIELD_USERNAME_CHARSET_REQUIRED="This characters in 'username' are not allowed: '%s'"
COM_USERS_CONFIG_FIELD_USERNAME_EMAIL_REQUIRED="The username field must be a valid email adress."
COM_USERS_CONFIG_FIELD_USERNAME_IDSTART_REQUIRED="First character in username must be a letter."
COM_USERS_CONFIG_FIELD_USERNAME_IDCONTINUE_REQUIRED="This characters don't fit the Unicode Default Identifier Syntax: %s"
COM_USERS_CONFIG_FIELD_USERNAME_IDPROFILE_REQUIRED="There are characters in username not allowed by Unicode Consortium for being part of an identifier. This characters are: %s"
COM_USERS_CONFIG_FIELD_USERNAME_LATIN_REQUIRED="Only latin characters are allowed in username field. This characters are not latin: %s"
COM_USERS_CONFIG_FIELD_USERNAME_M3AAWG_REQUIRED="Only this combinations are allowed for East Asian Languages in accordance with M3AAWG best practices for username field: [Latin + Han + Hiragana + Katakana] OR [Latin + Han + Bopomofo] OR [Latin + Han + Hangul]"
COM_USERS_CONFIG_FIELD_USERNAME_MAXNUMCHARS_REQUIRED="The username field should contain a maximum of %d characters, but you give %d."
COM_USERS_CONFIG_FIELD_USERNAME_MINNUMCHARS_REQUIRED="The username field should contain a minimum of %d characters. You only give %d."
COM_USERS_CONFIG_FIELD_USERNAME_NOOPTION="Option not allowed."
COM_USERS_CONFIG_FIELD_USERNAME_ONESCRIPT_REQUIRED="Only characters from one language are allowed for username."
COM_USERS_DATABASE_ERROR="Error getting the user from the database: %s"
COM_USERS_DESIRED_PASSWORD="Enter your desired password."
COM_USERS_DESIRED_USERNAME="Enter your desired username."
Expand Down
12 changes: 12 additions & 0 deletions language/en-GB/en-GB.lib_joomla.ini
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,18 @@ JLIB_RULES_CALCULATED_SETTING="Calculated Setting"
JLIB_RULES_CONFLICT="Conflict"
JLIB_RULES_DATABASE_FAILURE="Failed storing the data to the database."
JLIB_RULES_DENIED="Denied"
JLIB_RULES_FIELD_USERNAME_ALPHANUMERIC_REQUIRED="Only alphanumeric characters for username field are allowed."
JLIB_RULES_FIELD_USERNAME_CHARSET_REQUIRED="This characters in 'username' are not allowed: '%s'"
JLIB_RULES_FIELD_USERNAME_EMAIL_REQUIRED="The username field must be a valid email adress."
JLIB_RULES_FIELD_USERNAME_IDSTART_REQUIRED="First character in username must be a letter."
JLIB_RULES_FIELD_USERNAME_IDCONTINUE_REQUIRED="This characters don't fit the Unicode Default Identifier Syntax: %s"
JLIB_RULES_FIELD_USERNAME_IDPROFILE_REQUIRED="There are characters in username not allowed by Unicode Consortium for being part of an identifier. This characters are: %s"
JLIB_RULES_FIELD_USERNAME_LATIN_REQUIRED="Only latin characters are allowed in username field. This characters are not latin: %s"
JLIB_RULES_FIELD_USERNAME_M3AAWG_REQUIRED="Only this combinations are allowed for East Asian Languages in accordance with M3AAWG best practices for username field: [Latin + Han + Hiragana + Katakana] OR [Latin + Han + Bopomofo] OR [Latin + Han + Hangul]"
JLIB_RULES_FIELD_USERNAME_MAXNUMCHARS_REQUIRED="The username field should contain a maximum of %d characters, but you give %d."
JLIB_RULES_FIELD_USERNAME_MINNUMCHARS_REQUIRED="The username field should contain a minimum of %d characters. You only give %d."
JLIB_RULES_FIELD_USERNAME_NOOPTION="Option not allowed."
JLIB_RULES_FIELD_USERNAME_ONESCRIPT_REQUIRED="Only characters from one language are allowed for username."
JLIB_RULES_GROUP="%s"
JLIB_RULES_GROUPS="Groups"
JLIB_RULES_INHERIT="Inherit"
Expand Down
12 changes: 10 additions & 2 deletions libraries/joomla/form/rule/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,16 @@ public function test(SimpleXMLElement $element, $value, $group = null, Registry
}

// Check if the email is blacklisted by the user
$params = JComponentHelper::getParams('com_users');
$emailPreset = $params->get('custom_chars_email');
$component = array_key_exists('component', $element) ? (string) $element['component'] : 'com_users';
$params = JComponentHelper::getParams($component);

$emailPreset = $params->get('custom_chars_email', '');

if ('' === $emailPreset)
{
return true;
}

$presets = preg_split('/\r\n|\n|\r/', $emailPreset);

// Check all entries
Expand Down
50 changes: 30 additions & 20 deletions libraries/joomla/form/rule/username.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ public function test(SimpleXMLElement $element, $value, $group = null, Registry
$result = true;
$app = JFactory::getApplication();

// Load language files
JFactory::getLanguage()->load('com_users');

// Get the database object and a new query object.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
Expand All @@ -66,45 +63,50 @@ public function test(SimpleXMLElement $element, $value, $group = null, Registry
}

// Get the config params for username
$params = JComponentHelper::getParams('com_users');
$component = array_key_exists('component', $element) ? (string) $element['component'] : 'com_users';
$params = JComponentHelper::getParams($component);

// CHECK MINIMUM CHARACTER'S NUMBER
// Get the number of characters in $username
$usernameLength = StringHelper::strlen($value);

// Get the minimum number of characters
$minNumChars = $params->get('minimum_length_username');
$minNumChars = $params->get('minimum_length_username', 0);

// If is set minNumChars and $usernameLength does't achieve minimum lenght
if (($minNumChars) && ($usernameLength < $minNumChars))
{
$app->enqueueMessage(JText::sprintf('COM_USERS_CONFIG_FIELD_USERNAME_MINNUMCHARS_REQUIRED', $minNumChars, $usernameLength), 'warning');
$app->enqueueMessage(JText::sprintf('JLIB_RULES_FIELD_USERNAME_MINNUMCHARS_REQUIRED', $minNumChars, $usernameLength), 'warning');
$result = false;
}

// CHECK MAXIMUM CHARACTER'S NUMBER
// Get the maximum number of characters
$maxNumChars = $params->get('maximum_length_username');
$maxNumChars = $params->get('maximum_length_username', 0);

// If is set maxNumChars and $usernameLength surpass maximum lenght
if (($maxNumChars) && ($usernameLength > $maxNumChars))
{
$app->enqueueMessage(JText::sprintf('COM_USERS_CONFIG_FIELD_USERNAME_MAXNUMCHARS_REQUIRED', $maxNumChars, $usernameLength), 'warning');
$app->enqueueMessage(JText::sprintf('JLIB_RULES_FIELD_USERNAME_MAXNUMCHARS_REQUIRED', $maxNumChars, $usernameLength), 'warning');
$result = false;
}

// CHECK IF USERNAME SPELLING IN ALLOWED CHARACTER SET
// Get preset option
$allowed_preset = $params->get('allowed_chars_username_preset');
$allowed_preset = $params->get('allowed_chars_username_preset', 0);

if ($allowed_preset)
{
switch ($allowed_preset)
{
case 1: // CUSTOM ALLOWED
case 2: // CUSTOM FORBIDDEN
$customCharsUsername = array_unique(StringHelper::str_split($params->get('custom_chars_username')));
$customCharsUsername = array_unique(StringHelper::str_split($params->get('custom_chars_username', '')));

if ('' === $customCharsUsername)
{
break;
}
// Get the username
$uname = array_unique(StringHelper::str_split($value));

Expand All @@ -122,24 +124,32 @@ public function test(SimpleXMLElement $element, $value, $group = null, Registry
// Check if all the $uname chars are valid chars
if (!empty($invalid_chars))
{
$app->enqueueMessage(JText::sprintf('COM_USERS_CONFIG_FIELD_USERNAME_CHARSET_REQUIRED', implode('', $invalid_chars)), 'warning');
$app->enqueueMessage(JText::sprintf('JLIB_RULES_FIELD_USERNAME_CHARSET_REQUIRED', implode('', $invalid_chars)), 'warning');
$result = false;
}
break;

case 3:
// CUSTOM IS REGEXP
// All that match is rejected
$regExp = (string) $params->get('custom_chars_username');
$regExp = (string) $params->get('custom_chars_username', '');

if ('' === $regExp)
{
break;
}

if (preg_match_all($regExp, $value, $regExpChars))
{
$nonRegExpString = preg_replace($regExp, '', $value);

// Enqueue error message and return false
$app->enqueueMessage(JText::sprintf('COM_USERS_CONFIG_FIELD_USERNAME_CHARSET_REQUIRED', $nonRegExpString), 'warning');
if ('' !== $nonRegExpString)
{
$app->enqueueMessage(JText::sprintf('JLIB_RULES_FIELD_USERNAME_CHARSET_REQUIRED', $nonRegExpString), 'warning');

$result = false;
$result = false;
}
}
break;
case 4:
Expand All @@ -150,7 +160,7 @@ public function test(SimpleXMLElement $element, $value, $group = null, Registry
if (!ctype_alnum($value))
{
// Enqueue error message and return false
$app->enqueueMessage(JText::sprintf('COM_USERS_CONFIG_FIELD_USERNAME_ALPHANUMERIC_REQUIRED'), 'warning');
$app->enqueueMessage(JText::sprintf('JLIB_RULES_FIELD_USERNAME_ALPHANUMERIC_REQUIRED'), 'warning');

$result = false;
}
Expand All @@ -163,7 +173,7 @@ public function test(SimpleXMLElement $element, $value, $group = null, Registry
$nonLatinString = implode(' ', array_unique($nonLatinChars[0]));

// Enqueue error message and return false
$app->enqueueMessage(JText::sprintf('COM_USERS_CONFIG_FIELD_USERNAME_LATIN_REQUIRED', $nonLatinString), 'warning');
$app->enqueueMessage(JText::sprintf('JLIB_RULES_FIELD_USERNAME_LATIN_REQUIRED', $nonLatinString), 'warning');

$result = false;
}
Expand Down Expand Up @@ -194,7 +204,7 @@ public function test(SimpleXMLElement $element, $value, $group = null, Registry
if (!preg_match_all($regexRecommendedScripts, $valueWithoutCommonInherited))
{
// Enqueue error message and return false
$app->enqueueMessage(JText::sprintf('COM_USERS_CONFIG_FIELD_USERNAME_ONESCRIPT_REQUIRED'), 'warning');
$app->enqueueMessage(JText::sprintf('JLIB_RULES_FIELD_USERNAME_ONESCRIPT_REQUIRED'), 'warning');

$result = false;
}
Expand Down Expand Up @@ -261,7 +271,7 @@ public function test(SimpleXMLElement $element, $value, $group = null, Registry
}

// Enqueue error message and return false
$app->enqueueMessage(JText::sprintf('COM_USERS_CONFIG_FIELD_USERNAME_IDPROFILE_REQUIRED', $nonIdentifierProfileString), 'warning');
$app->enqueueMessage(JText::sprintf('JLIB_RULES_FIELD_USERNAME_IDPROFILE_REQUIRED', $nonIdentifierProfileString), 'warning');

$result = false;
}
Expand Down Expand Up @@ -298,15 +308,15 @@ public function test(SimpleXMLElement $element, $value, $group = null, Registry
if (!JMailHelper::isEmailAddress($value) )
{
// Enqueue error message and return false
$app->enqueueMessage(JText::_('COM_USERS_CONFIG_FIELD_USERNAME_EMAIL_REQUIRED'), 'warning');
$app->enqueueMessage(JText::_('JLIB_RULES_FIELD_USERNAME_EMAIL_REQUIRED'), 'warning');

$result = false;
}
break;

default:
// NO OPTION
$app->enqueueMessage(JText::_('COM_USERS_CONFIG_FIELD_USERNAME_NOOPTION'), 'warning');
$app->enqueueMessage(JText::_('JLIB_RULES_FIELD_USERNAME_NOOPTION'), 'warning');

return false;
}
Expand Down

0 comments on commit 809f68a

Please sign in to comment.