? ? Failure

User tests: Successful: 0 Unsuccessful: 0

avatar carlitorweb
carlitorweb
1 May 2018

Pull Request for Issue #20249

Summary of Changes

Added onContentPrepareForm event to the plugin for doing the form require alterations to the passwords fields.

Testing Instructions

Go to the administration and create a new user. Check the form that is shown need have the passwords fields with the attribute "require" if the plugin User - Joomla! have the Notification Mail to User option as No.

Expected result

Passwords field with the "require" attribute

Actual result

Passwords field with the "require" attribute

Documentation Changes Required

No

avatar carlitorweb carlitorweb - open - 1 May 2018
avatar carlitorweb carlitorweb - change - 1 May 2018
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 1 May 2018
Category Administration com_users Front End Plugins
avatar carlitorweb carlitorweb - change - 1 May 2018
Labels Added: ?
avatar carlitorweb
carlitorweb - comment - 1 May 2018

Done @zero-24 and thank you

avatar zero-24
zero-24 - comment - 2 May 2018

I have just tested this and found two issue. In case there is a validation error $data is no stdClass but just an empty array. And the second is what happen when the plugin is disabled. Currently the password field is not required. But it needs to be required than.

How to reproduce (First Issue)

  • set error reporting to max
  • create a user with the username test
  • try to create another user with the same username
  • error pops up.
  • when you debug you notice that the $data array is empty.

How to reproduce (Second Issue)

  • Disable the plugin
  • try to create a user
  • pw field is not required.

How to solve the issues

  • change default in com_users XML file that the pw's are always required
  • restructure the plugin check so it disable the required status if running.
avatar carlitorweb
carlitorweb - comment - 3 May 2018

Disable the plugin

@zero-24 if you disabled the plugin, others things like the login logic will break, among other things. In fact, there is a string warning about this. In case this plugin is disabled because another plugin will handle User synchronization, then we no need more the "Notification Mail to User", and we no need check for this.

try to create another user with the same username

We can add an is_object() check inside the condition for avoiding this

avatar carlitorweb
carlitorweb - comment - 4 May 2018

I do not understand why the drone fail here?

avatar zero-24
zero-24 - comment - 4 May 2018

In case this plugin is disabled because another plugin will handle User synchronization, then we no need more the "Notification Mail to User", and we no need check for this.

Well my point is that the password fields are than not required in that case ;)
So my suggestion was to change the logic so the fields are required allways but not required with the setting is enabeld ;)

But I'm also fine merge this without that change and when this got accepted i do a PR that would handle the proposed solution.

avatar carlitorweb
carlitorweb - comment - 9 May 2018

@Quy can you give me a hand here? This code is marked as a conflict for the merge, was moved to the plugin for solved the issue. Or maybe I understand wrong this.

avatar Quy
Quy - comment - 9 May 2018

I think you have to update your branch since there were changes to administrator/components/com_users/models/user.php 4 days ago.

avatar carlitorweb
carlitorweb - comment - 9 May 2018

Thank you @Quy

avatar carlitorweb
carlitorweb - comment - 25 May 2018

Thank you @SharkyKZ

avatar Quy
Quy - comment - 26 May 2018

Create a duplicate user.
An error message is displayed.
Password and Confirm Password are no longer marked required.

#14851 and #20313 could be related to this issue.

avatar SharkyKZ
SharkyKZ - comment - 28 May 2018

Data from user state is an array https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_users/models/user.php#L172.

This seems to be the case everywhere else.

avatar carlitorweb
carlitorweb - comment - 31 May 2018

I made what @SharkyKZ suggest before:

change default in com_users XML file that the pw's are always required
restructure the plugin check so it disable the required status if running.

Please, can you test again @Quy . Also, as the password field is required by default, we need to remove this, when we edit a user.

PD: Sorry for the delay

avatar Quy
Quy - comment - 31 May 2018

On the backend, Password and Confirm Password are not required (right). After an error, these fields are marked required (wrong).

avatar carlitorweb
carlitorweb - comment - 31 May 2018

On the backend, Password and Confirm Password are not required (right)

So, change the pw´s fields required by default is wrong?

avatar Quy
Quy - comment - 31 May 2018

On the backend, leave the password blank for the system to auto generate the password. Without PR, the 2 password fields are not required. With PR, the password fields are not required initially, but after a duplicate error, they are marked required.

avatar carlitorweb
carlitorweb - comment - 31 May 2018

@Quy now I got it. Sorry for be slow, sometime my English is not so good as I want it.
So, with this PR and plugin User - Joomla, with the Notification Mail to User set on No passwords fields are required (Correct operation). But if you save a duplicate user, then passwords fields after get the error, are not required (Wrong operation, need stay as required).

Checking this, somehow $options['load_data'] come with the value false when you save a duplicate user,

if (isset($options['load_data']) && $options['load_data'])
then, preprocessForm(...) trigger the plugin passing an empty $data, so that make the check inside onContentPrepareForm event fail.

avatar Quy
Quy - comment - 31 May 2018

Youre English fine to me. ?

Please read the following about password on the backend: #20247 (comment)

I was wrong with my report. I think your PR is fine, but I will have to test again to be sure.

avatar carlitorweb
carlitorweb - comment - 31 May 2018

Please read the following about password on the backend

Thank you

avatar SharkyKZ
SharkyKZ - comment - 1 Jun 2018

The issue is that on validation error returned data is an array. This could probably be fixed in core, but for now you can remove is_object() check and cast data as object.

avatar Quy
Quy - comment - 1 Jun 2018

Tested @ 9e333a9

PHP Notice: Undefined property: stdClass::$id in \plugins\user\joomla\joomla.php on line 58

avatar SharkyKZ
SharkyKZ - comment - 1 Jun 2018

@Quy how do you get this notice?

avatar Quy
Quy - comment - 1 Jun 2018

Check in the PHP error log file.

avatar SharkyKZ
SharkyKZ - comment - 1 Jun 2018

FormController never loads form data so whatever form data check is performed in plugin is not valid when saving.

$form = $model->getForm($data, false);

Assuming this is intended and no changes should be made to models or controllers, see System - Fields plugin for a solution:
$input = JFactory::getApplication()->input;
// If we are on the save command we need the actual data
$jformData = $input->get('jform', array(), 'array');
if ($jformData && !$data)
{
$data = $jformData;
}
if (is_array($data))
{
$data = (object) $data;
}

avatar carlitorweb
carlitorweb - comment - 5 Jun 2018

Thank you @SharkyKZ and @Quy .

avatar Quy
Quy - comment - 6 Jun 2018

Sorry I gave you wrong information prior. Here is the right information:

On the back end, when Notification Mail to User is No, then Password and Confirm Password should be marked with * and be required.

Your PR, however, after an error, these 2 fields are no longer marked with *.

avatar SharkyKZ
SharkyKZ - comment - 6 Jun 2018

This isn't right yet. On form display, $data is always populated. It's normally an object but an array after returning from error. Data from input ($jformData) is not available on form display.

On save, $data is an empty array because FormController does not load data. So on save you need to use data from input ($jformData).

This is indeed #14851.

The same issue exists without PR. When Notification Mail to User is set to No password fields appear to be required on form display but aren't validated on save. To test this, remove required attribute and class from markup using browser's developer tools and submit the form without passwords. The user will be saved.

avatar carlitorweb
carlitorweb - comment - 6 Jun 2018

The real fix is try to handle this from the model or the controller. But I can bet will be B/C issue.

Your PR, however, after an error, these 2 fields are no longer marked with *

Is true, I do not see this. However, if you try to save again, you get a warning telling you, the password field is required.

avatar carlitorweb
carlitorweb - comment - 7 Jun 2018

@Quy I does not understand why, when we get the error the * gone. Even if you save, you got the warning saying the password is required, but no put the field as required in the HTML markup. Can you give me a hand with this? I try to find where I miss something, but no luck for now

avatar SharkyKZ
SharkyKZ - comment - 7 Jun 2018

It's because of the check in the plugin. Replace this:

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

With this:

if ($jformData && !$data) 
 { 
 	$data = $jformData; 
 } 
  
if (is_array($data)) 
{ 
 	$data = (object) $data; 
} 
avatar carlitorweb
carlitorweb - comment - 7 Jun 2018

Thank you @SharkyKZ , that was But or I need close all here and go to watch a movie, or is almost the same I had in the check before :D . Anyway, thank you for the help

avatar carlitorweb
carlitorweb - comment - 7 Jun 2018

Done, thank @Quy

avatar Quy
Quy - comment - 10 Jun 2018

Related issue #17700 about empty $data.

avatar carlitorweb
carlitorweb - comment - 20 Jun 2018

This is the correct way then to do this or need a different way?

avatar SharkyKZ
SharkyKZ - comment - 27 Jun 2018

The code works fine now.

Still thinking about @zero-24's suggestion to make password fields required by default. It would make sense not to auto-generate passwords when plugin is disabled, when mail to user option in plugin is disabled or when sending passwords is disabled in com_users.

avatar carlitorweb
carlitorweb - comment - 27 Jun 2018

Ok, let do the suggestion of @zero-24

avatar brianteeman
brianteeman - comment - 27 Jun 2018

It never makes sense in the admin to make creating a password required.

avatar mbabker
mbabker - comment - 27 Jun 2018

It never makes sense in the admin to make creating a password required.

For creating a new account, I'd say it would make sense to default it to required and conditionally unrequire it based on the other settings. Otherwise you're left in a spot where admin creates an account without setting a password and the new user's only way of getting into the account is through the "forgot my password" interface. I don't think that's necessarily the best new user experience, but we all know what opinions are like.

avatar carlitorweb
carlitorweb - comment - 27 Jun 2018

This is a valid argument imo #20247 (comment)

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 21 Jul 2019

@carlitorweb are the Test Instructions up-to-date?

avatar carlitorweb
carlitorweb - comment - 22 Jul 2019

@fran so far, yes

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 23 Jul 2019

"Notification Mail to User"-option is "No", both Password-Fields have a "*". I'm confused about the Test Instructions.

Also "Expected" and "Actual Result" have the same Description.

avatar SharkyKZ
SharkyKZ - comment - 2 Sep 2019

@franz-wohlkoenig Behavior before and after patch should be the same.

avatar SharkyKZ SharkyKZ - test_item - 2 Sep 2019 - Tested successfully
avatar SharkyKZ
SharkyKZ - comment - 2 Sep 2019

I have tested this item successfully on fe03395


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/20275.

avatar Quy Quy - test_item - 14 Jan 2020 - Tested successfully
avatar Quy
Quy - comment - 14 Jan 2020

I have tested this item successfully on b633bbf


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/20275.

avatar Quy Quy - change - 14 Jan 2020
Status Pending Ready to Commit
avatar Quy
Quy - comment - 14 Jan 2020

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/20275.

avatar Quy
Quy - comment - 14 Jan 2020

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/20275.

avatar HLeithner HLeithner - change - 22 Jan 2020
Labels Added: ?
avatar HLeithner HLeithner - close - 22 Jan 2020
avatar HLeithner HLeithner - merge - 22 Jan 2020
avatar HLeithner
HLeithner - comment - 22 Jan 2020

Thanks

avatar HLeithner HLeithner - change - 22 Jan 2020
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2020-01-22 21:38:20
Closed_By HLeithner

Add a Comment

Login with GitHub to post a comment