Skip to content

Commit

Permalink
Implement AJAX user changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mxkmp29 authored and mxkmp29 committed Aug 9, 2016
1 parent ff7e512 commit 17bbe6a
Show file tree
Hide file tree
Showing 10 changed files with 736 additions and 212 deletions.
96 changes: 95 additions & 1 deletion administrator/components/com_users/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@
step="1"
default="1">
</field>

</fieldset>

<fieldset
name="password"
label="COM_USERS_CONFIG_PASSWORD_OPTIONS" >

<field
name="minimum_length"
type="integer"
Expand Down Expand Up @@ -185,7 +190,77 @@
default="0">
</field>
</fieldset>

<fieldset
name="username"
label="COM_USERS_CONFIG_USERNAME_OPTIONS" >

<field
name="minimum_length_username"
type="integer"
label="COM_USERS_CONFIG_FIELD_USERNAME_MINNUMCHARS_LABEL"
description="COM_USERS_CONFIG_FIELD_USERNAME_MINNUMCHARS_DESC"
first="0"
last="99"
step="1">
</field>

<field
name="maximum_length_username"
type="integer"
label="COM_USERS_CONFIG_FIELD_USERNAME_MAXNUMCHARS_LABEL"
description="COM_USERS_CONFIG_FIELD_USERNAME_MAXNUMCHARS_DESC"
first="0"
last="99"
step="1">
</field>

<field
name="allowed_chars_username_preset"
type="list"
label="COM_USERS_CONFIG_FIELD_USERNAME_CHARSPRESET_LABEL"
description="COM_USERS_CONFIG_FIELD_USERNAME_CHARSPRESET_DESC"
filter="integer"
defaut="0"
>
<option value="0">
COM_USERS_CONFIG_FIELD_USERNAME_CHARSPRESET_OPTION_DISABLECHECK
</option>
<option value="1">
COM_USERS_CONFIG_FIELD_USERNAME_CHARSPRESET_OPTION_CUSTOM_ALLOWED
</option>
<option value="2">
COM_USERS_CONFIG_FIELD_USERNAME_CHARSPRESET_OPTION_CUSTOM_FORBIDDEN
</option>
<option value="3">
COM_USERS_CONFIG_FIELD_USERNAME_CHARSPRESET_OPTION_CUSTOM_REGEXP
</option>
<option value="4">
COM_USERS_CONFIG_FIELD_USERNAME_CHARSPRESET_OPTION_ALPHANUMERIC
</option>
<option value="5">
COM_USERS_CONFIG_FIELD_USERNAME_CHARSPRESET_OPTION_LATIN
</option>
<option value="6">
COM_USERS_CONFIG_FIELD_USERNAME_CHARSPRESET_OPTION_UNICODE_HIGHLY_RESTRICTIVE
</option>
<option value="7">
COM_USERS_CONFIG_FIELD_USERNAME_CHARSPRESET_OPTION_EMAIL
</option>
</field>

<field
name="custom_chars_username"
type="textarea"
label="COM_USERS_CONFIG_FIELD_USERNAME_CHARSET_LABEL"
description="COM_USERS_CONFIG_FIELD_USERNAME_CHARSET_DESC"
rows="4"
cols="50"
filter="string"
>
</field>
</fieldset>

<fieldset
name="user_notes_history"
label="COM_USERS_CONFIG_FIELD_NOTES_HISTORY" >
Expand Down Expand Up @@ -236,6 +311,25 @@

</fieldset>

<fieldset name="integration"
label="JGLOBAL_INTEGRATION_LABEL"
description="COM_USERS_CONFIG_INTEGRATION_SETTINGS_DESC"
>

<field
name="sef_advanced"
type="radio"
class="btn-group btn-group-yesno"
default="0"
label="JGLOBAL_SEF_ADVANCED_LABEL"
description="JGLOBAL_SEF_ADVANCED_DESC"
filter="integer">
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>

</fieldset>

<fieldset
name="permissions"
label="JCONFIG_PERMISSIONS_LABEL"
Expand Down
20 changes: 20 additions & 0 deletions administrator/language/en-GB/en-GB.com_users.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ COM_USERS_CONFIG_FIELD_CAPTCHA_DESC="Select the captcha plugin that will be used
COM_USERS_CONFIG_FIELD_CAPTCHA_LABEL="Captcha"
COM_USERS_CONFIG_FIELD_CHANGEUSERNAME_DESC="Allow users to change their Login name when editing their profile."
COM_USERS_CONFIG_FIELD_CHANGEUSERNAME_LABEL="Change Login Name"
COM_USERS_CONFIG_FIELD_EMAIL_REGEX_LABEL="Forbidden domains"
COM_USERS_CONFIG_FIELD_EMAIL_REGEX_DESC="Expression for forbidden email adress endings. Example: Forbid all email addresses from example.com. Input:<br /> example.com<br />For many entries add a new line after every entry. <br />Input: <br />example.com<br />example2.com"
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 Down Expand Up @@ -67,10 +69,28 @@ 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_USERNAME_CHARSPRESET_LABEL="Characters preset"
COM_USERS_CONFIG_FIELD_USERNAME_CHARSPRESET_DESC="Specify from the select list if you want disable this check or allow/forbid CUSTOM characters filling the CUSTOM text box. You can also select some of the specified character presettings: alphanumeric, latin, email,..."
COM_USERS_CONFIG_FIELD_USERNAME_MINNUMCHARS_LABEL="MINimum number of characters"
COM_USERS_CONFIG_FIELD_USERNAME_MINNUMCHARS_DESC="MINimum number of characters required for username field. Zero indicates no limit."
COM_USERS_CONFIG_FIELD_USERNAME_MAXNUMCHARS_LABEL="MAXimum number of characters"
COM_USERS_CONFIG_FIELD_USERNAME_MAXNUMCHARS_DESC="MAXimum number of characters required for username field. Zero indicates no limit."
COM_USERS_CONFIG_FIELD_USERNAME_CHARSET_LABEL="CUSTOM character set"
COM_USERS_CONFIG_FIELD_USERNAME_CHARSET_DESC="CUSTOM character set ALLOWED/FORBIDDEN/REGEXP for username field. Select the appropriate behaviour in previous select list. If other than 'CUSTOM' is selected, this text box is not operational. Example allow/forbid: write 'abc' (without quotations) to allow/forbid these characters. For 'CUSTOM REGEXP' case, write a pattern to use inside a preg_match_all() function and all that match will be forbidden. Example regExp for 'latin only': '/[^\\\\\\\\p{Common}\\\\\\\\p{Latin}]/u' (without quotations)."
COM_USERS_CONFIG_FIELD_USERNAME_CHARSPRESET_OPTION_DISABLECHECK="DISABLE characters check"
COM_USERS_CONFIG_FIELD_USERNAME_CHARSPRESET_OPTION_CUSTOM_ALLOWED="CUSTOM is characters allowed"
COM_USERS_CONFIG_FIELD_USERNAME_CHARSPRESET_OPTION_CUSTOM_FORBIDDEN="CUSTOM is characters forbidden"
COM_USERS_CONFIG_FIELD_USERNAME_CHARSPRESET_OPTION_CUSTOM_REGEXP="CUSTOM is a regular expression"
COM_USERS_CONFIG_FIELD_USERNAME_CHARSPRESET_OPTION_ALPHANUMERIC="Alphanumeric Only"
COM_USERS_CONFIG_FIELD_USERNAME_CHARSPRESET_OPTION_LATIN="Latin Only"
COM_USERS_CONFIG_FIELD_USERNAME_CHARSPRESET_OPTION_EMAIL="Email valid address"
COM_USERS_CONFIG_FIELD_USERNAME_CHARSPRESET_OPTION_UNICODE_HIGHLY_RESTRICTIVE="Unicode Security: Highly Restrictive level"
COM_USERS_CONFIG_IMPORT_FAILED="An error was encountered while importing the configuration: %s."
COM_USERS_CONFIG_PASSWORD_OPTIONS="Password Options"
COM_USERS_CONFIG_SAVE_FAILED="An error was encountered while saving the configuration: %s."
COM_USERS_CONFIG_PASSWORD_OPTIONS="Password options"
COM_USERS_CONFIG_USER_OPTIONS="User Options"
COM_USERS_CONFIG_USERNAME_OPTIONS="Username options"
COM_USERS_CONFIGURATION="Users: Options"
COM_USERS_COUNT_ENABLED_USERS="Enabled users"
COM_USERS_COUNT_DISABLED_USERS="Disabled users"
Expand Down
74 changes: 74 additions & 0 deletions components/com_users/controllers/registration.json.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_users
*
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;
require_once JPATH_COMPONENT . '/controller.php';

/**
* Profile controller class for Users.
*
* @since 1.6
*/
class UsersControllerRegistration extends UsersController
{
/**
*
* Method to validate a username.
* @return void
* @since 3.7
*
*/

public function validate()
{
//read username from ajax
$username = $this->input->get('username', '', 'username');
$email = $this->input->get('email', '', 'email');

//check
if(!empty($username))
{
$fieldname = 'username';
$field = $username;
}
else if(!empty($email))
{
$fieldname = 'email';
$field = $email;
}

if(isset($fieldname) && isset($field))
{
$db = JFactory::getDbo();

$valid = $db->setQuery(
$db->getQuery(true)
->select($fieldname)
->from('#__users')
->where($fieldname . ' = ' . $db->quote($field))
)->loadResult();

//return jsonarray with results
$msg = null;
if(!is_null($valid))
{
if($fieldname == 'username')
{
$msg = JText::_('COM_USERS_REGISTER_USERNAME_MESSAGE');
}else if($fieldname == 'email')
{
$msg = JText::_('COM_USERS_PROFILE_EMAIL1_MESSAGE');
}
}
echo new JResponseJson($valid, $msg, is_null($valid));
}


}
}
2 changes: 2 additions & 0 deletions components/com_users/controllers/registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,6 @@ public function register()

return true;
}


}
3 changes: 1 addition & 2 deletions components/com_users/views/registration/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

defined('_JEXEC') or die;

/**
* Registration view class for Users.
*
Expand Down Expand Up @@ -109,7 +108,7 @@ protected function prepareDocument()
}

$this->document->setTitle($title);

//this->document
if ($this->params->get('menu-meta_description'))
{
$this->document->setDescription($this->params->get('menu-meta_description'));
Expand Down
2 changes: 2 additions & 0 deletions libraries/cms/html/behavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ public static function formvalidator()

// Add validate.js language strings
JText::script('JLIB_FORM_FIELD_INVALID');
JText::script('COM_USERS_PROFILE_EMAIL2_MESSAGE');
JText::script('COM_USERS_FIELD_RESET_PASSWORD1_MESSAGE');

JHtml::_('script', 'system/punycode.js', false, true);
JHtml::_('script', 'system/validate.js', false, true);
Expand Down
18 changes: 18 additions & 0 deletions libraries/joomla/form/rule/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,24 @@ 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');
$presets = preg_split ('/\r\n|\n|\r/', $emailPreset);

//check all entries
foreach ($presets as $regex)
{
if($regex != '' && $regex != '*') { //skip new lines
$regex = '/(.*)@' . $regex . '/';
preg_match($regex, $value, $output);

if ($output) {
return false;
}
}
}

// Check if we should test for uniqueness. This only can be used if multiple is not true
$unique = ((string) $element['unique'] == 'true' || (string) $element['unique'] == 'unique');

Expand Down

0 comments on commit 17bbe6a

Please sign in to comment.