Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Hard Coupling (com_users | plg_users_joomla) #20275

Merged
merged 25 commits into from Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
28edf5c
Fixed Hard Coupling (com_users | plg_users_joomla)
carlitorweb May 1, 2018
1c056ec
Code review. Dropped instanceof JForm check
carlitorweb May 1, 2018
ab35379
Code review
carlitorweb May 1, 2018
239a5fd
Code review
carlitorweb May 1, 2018
74b96eb
Fixed issue when username is same
carlitorweb May 3, 2018
7c05d6c
Fix drone
carlitorweb May 4, 2018
feec4ba
Fix drone
carlitorweb May 4, 2018
7ee9641
Merge branch 'staging' into hard_coupling_users
carlitorweb May 9, 2018
327ec06
CS fixed
carlitorweb May 9, 2018
3a5b6e3
Codereview
carlitorweb May 25, 2018
86ee607
Change password field required as default
carlitorweb May 31, 2018
5f504cc
Restructure the plugin check so it disable the required status if run…
carlitorweb May 31, 2018
8cad84d
Pasword field is not required when we edit a user
carlitorweb May 31, 2018
f4f3704
Revert "Pasword field is not required when we edit a user"
carlitorweb May 31, 2018
040a7ac
Revert "Restructure the plugin check so it disable the required statu…
carlitorweb May 31, 2018
ae8fe3a
Revert "Change password field required as default"
carlitorweb May 31, 2018
9e333a9
Casting $data
carlitorweb Jun 1, 2018
7a16367
Casting $data
carlitorweb Jun 5, 2018
3bd5533
Cast $data
carlitorweb Jun 7, 2018
420d6e4
Code review
carlitorweb Jun 7, 2018
ec4581c
Code review
carlitorweb Jun 7, 2018
fe03395
Code review
carlitorweb Jun 8, 2018
d7a60f9
Merge branch 'staging' into hard_coupling_users
Dec 5, 2019
b633bbf
Merge branch 'staging' into hard_coupling_users
Jan 12, 2020
bf9ec93
Merge branch 'staging' into hard_coupling_users
HLeithner Jan 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 2 additions & 17 deletions administrator/components/com_users/models/user.php
Expand Up @@ -112,14 +112,6 @@ public function getItem($pk = null)
*/
public function getForm($data = array(), $loadData = true)
{
$pluginParams = new Registry;

if (JPluginHelper::isEnabled('user', 'joomla'))
{
$plugin = JPluginHelper::getPlugin('user', 'joomla');
$pluginParams->loadString($plugin->params);
}

// Get the form.
$form = $this->loadForm('com_users.user', 'user', array('control' => 'jform', 'load_data' => $loadData));

Expand All @@ -128,15 +120,6 @@ public function getForm($data = array(), $loadData = true)
return false;
}

$userId = $form->getValue('id');

// Passwords fields are required when mail to user is set to No in the joomla user plugin
if ($userId === 0 && $pluginParams->get('mail_to_user', '1') === '0')
{
$form->setFieldAttribute('password', 'required', 'true');
$form->setFieldAttribute('password2', 'required', 'true');
}

// If the user needs to change their password, mark the password fields as required
if (JFactory::getUser()->requireReset)
{
Expand All @@ -150,6 +133,8 @@ public function getForm($data = array(), $loadData = true)
$form->setFieldAttribute('language', 'type', 'frontend_language', 'params');
}

$userId = $form->getValue('id');

// The user should not be able to set the requireReset value on their own account
if ((int) $userId === (int) JFactory::getUser()->id)
{
Expand Down
40 changes: 40 additions & 0 deletions plugins/user/joomla/joomla.php
Expand Up @@ -34,6 +34,46 @@ class PlgUserJoomla extends JPlugin
*/
protected $db;

/**
* Set as required the passwords fields when mail to user is set to No
*
* @param JForm $form The form to be altered.
* @param mixed $data The associated data for the form.
*
* @return boolean
wilsonge marked this conversation as resolved.
Show resolved Hide resolved
*
wilsonge marked this conversation as resolved.
Show resolved Hide resolved
* @since __DEPLOY_VERSION__
*/
public function onContentPrepareForm($form, $data)
{
// Check we are manipulating a valid user form before modifying it.
$name = $form->getName();

if ($name === 'com_users.user')
{
// In case there is a validation error (like duplicated user), $data is not a stdClass but just an empty array
// TODO: Check inside the FormModel, for put the right associated data for the form
if (!$data)
{
$data = JFactory::getApplication()->input->get('jform', array(), 'array');
}
wilsonge marked this conversation as resolved.
Show resolved Hide resolved

if (is_array($data))
{
$data = (object) $data;
}

// Passwords fields are required when mail to user is set to No
if (empty($data->id) && !$this->params->get('mail_to_user', 1))
{
$form->setFieldAttribute('password', 'required', 'true');
$form->setFieldAttribute('password2', 'required', 'true');
}
}

return true;
}

/**
* Remove all sessions for the user name
*
Expand Down