OK, I have a problem with a 4.7.0-beta2 site which in essence is this:

1) Users cannot change passwords
2) Administrator cannot change password
3) Editing users results in ALL roles being selected

This is practically a default site - almost nothing has been changed and the problem has me completely flummoxed. I have re-installed the site and monitored the entire process and have even tried rolling back when the error occured but to no avail.

I am so keen to get this problem resolved that I am willing to give administrator access to help solve it. The site is currently on www.v-community.co.uk and you can log in and create yourself a new account if you want to in order to test that this is true and, if you can help with the problem, please contact me for the Administrator password.

I have also 'blogged' the entire routine that I followed in setting this site up and getting to the point where the problem reoccured. You can read the blog here.

I think this is a relatively easy problem for people to encounter so perhaps the urgency is greater than just my own little site. All help is greatly appreciated.

Regards

Patrick

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Patrick Nelson’s picture

Component: user system » user.module

All bets are off. I've found the problem and it is in version 1.543 of the user module.

This update breaks the system in the following way:

1) It is impossible to change the password (either as user 1 or as the user whose password it is)

2) Changing roles results in all roles being selected for that user.

At least, this is the result of this update on my version of beta-2 which is pretty much a standard install.

Does anyone else have this problem?

eaton’s picture

I'm seeing it on a fresh install from HEAD as well.

eaton’s picture

Title: If you can solve this, you're a genius » 4.7b2: User.module can't change password, roles

Doing some investigation, also changing the title to reflect the nature of the problem

puregin’s picture

Could you provide more detail:

Which version of PHP?

What is the behaviour that you're seeing? "users cannot change passwords" is not very descriptive - what steps must I follow to duplicate this behaviour? Alternatively, step by step, what did you do, what did you expect to see/experience, what did you in fact experience.

Could this be a duplicate of: http://drupal.org/node/40384

Thanks, Djun

eaton’s picture

Running today's HEAD, with a fresh database, on a Site5 server with PHP Version 4.4.0 and MySQL 4.0.25.

Create the first account, get the auto-generated password. Log in. Go to user/edit/1 and change the password. Save.

Log out, then log in with the new password -- username/password not recognized. Reset the password, get the reset email, log in using the one-time key, change the password -- same story.

Then, go back and try to log in using the original randomly generated password from account creation -- success!

Have to investigate the issue with roles, I've only seen the password issue personally.

Patrick Nelson’s picture

puregin,

I appreciate that "users cannot change passwords" is 'not very descriptive', as you put it, but if you read the whole of the first post, you will see a link to a blog which describes the whole process that I took which I think IS descriptive.

puregin’s picture

As a developer interested in fixing bugs, I like to see what I need to know about a bug in the issue that people file, IN ONE PLACE. Don't make me chase through half a dozen replies, and blogs on this or that server. It's a nice way to promote your blog, but not helpful to people trying to fix bugs.

Please read the guidelines for submitting issues at
http://drupal.org/node/317 and http://drupal.org/node/19279.

Thank you

chx’s picture

Assigned: Unassigned » chx

There was a user edit form submit model conversion. It's rather trivial to see that this issue means that function user_edit_submit is botched. Let me see...

chx’s picture

Assigned: chx » Unassigned

http://drupal.org/node/39179 now fixes the role checkboxes problem.

Password, however reveals a much deeper problem. hook_user needs a 'submit' op, much like hook_nodeapi needed. validate validates, submit changes. The two are mixed. I do not have the time to rearrange _user_edit_validate accordingly (and put a caller line into user_user). However, it should be quite clear what's needed now.

Patrick Nelson’s picture

Puregin,

As a developer interested in fixing bugs, I like to see what I need to know about a bug in the issue that people file, IN ONE PLACE. - That's why I put in my first post, "I have also 'blogged' the entire routine". If you took a couple of seconds to click the link, you would have seen that. If you also took those couple of seconds instead of jumping to conclusions about what the blog contained, you would find that it is not a "nice way to promote your (my) blog because that is not MY blog - I put it up there because I was trying to be helpful.

I will read the guidelines that you suggested, thank you very much for pointing them out, because I AM trying to be "helpful to people trying to fix bugs" as asked for of the entire community here. If some of the developers wonder why more people haven't got involved and are helping, perhaps it has something to do with receiving rudeness and ignorance and getting their heads bitten off by people with a "holier than thou" attitude whenever they do.

To Eaton and chx, thank you for trying to help and I apologise if I didn't explain things clearly enough in my first post.

chx’s picture

Status: Active » Needs work
FileSize
3.89 KB

Roles work. Passwords do not. I am pretty sure you would have problems with pictures too.

chx’s picture

I mean deleting pictures -- previously, validate unset them. Now you need to unset them in submit.

chx’s picture

Gordon reports , and he is right that pass1 and pass2 needs to be elements of the forms array. Something like

$form['passwords']['#theme'] = ...
$form['passwords']['pass1'] = array('#type' => 'password'...);
$form['passwords']['pass2'] = array('#type' => 'password'...);
alexis’s picture

Hi, any update on this?

chx’s picture

Assigned: Unassigned » chx

After talking with Dries, we agreed it's better if I finish.

hunmonk’s picture

FileSize
7.46 KB

chx: hope i'm not stepping on your toes here, but this bug has been outstanding for awhile, and it's fairly serious--so i took a crack at a solution. attached patch integrates your previous patch, and creates a new 'password_confirm' form element so that the password fields get properly built in the form api code. also, the validation code was broken for users trying to register for new accounts, so i fixed that up. lemme know if there's anything else that needs done to get this in.

hunmonk’s picture

Status: Needs work » Needs review
eaton’s picture

Status: Needs review » Needs work

Password and role changes are now working (Yay!) but it's now impossible to change ANY field if pass1 and pass2 aren't entered. That means that an admin cannot add new roles without altering a user's password...

hunmonk’s picture

FileSize
9.53 KB

eaton: indeed. i caught that shortly afterwards. now, six hours later, i think i've finally got things squared away. please test! i revamped the password_confirm form element, and moved all of the relevant form processing behavior into the element itself--much nicer :) now if you want a password_confirm form element, you just:

$form['name_of_element'] = array('#type' => 'password_confirm');

and that's it. as long as the passwords properly validate, you'll end up with:

$form_values['name_of_element'] at your disposal... :)

you even have the option of making the password_confirm element required or not, and any module can use it, since it's now a system form element.

i also temporarily fixed the user picture uploads. somebody needs to properly abstract that portion of the code, but i feel that's a seperate issue to be filed. please, let's get this committed if it tests out ok--it's been broken in HEAD for 11 days now--not good... :)

eaton’s picture

Status: Needs work » Reviewed & tested by the community

Role changes are working, user pictures are working, password changes are working, and password reset emails are working. The password-confirm form element is a great re-usable element, too. Definite +1.

chx’s picture

FileSize
9.64 KB

Chad, you are FANTASTIC! I changed the following:

  • As the process function had no logic inside, I simply moved the child elements into system_elements.
  • I changed a bit the call to #after_build so you can change the global form_values in #after_build. This change does not affect node previews and other #after_build functions -- I checked.

Otherwise, you are the man.

gordon’s picture

This is great, +1 please commit ASAP.

eaton’s picture

Just tested it on my install as well. Everything's good to go. +1

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)
ax’s picture

Version: » 4.7.3
Priority: Critical » Normal
Status: Closed (fixed) » Active

this patch adds a new op 'submit' to hook_user and should be documented at http://api.drupal.org/api/4.7/function/hook_user (and HEAD) and possibly Converting 4.6 modules to 4.7. marking ACTIVE until this is fixed. see also bug update documentation for hook_user, op 'submit'.

Darren Oh’s picture

Category: bug » task
magico’s picture

Title: 4.7b2: User.module can't change password, roles » hook_user() changed and should be documented
Project: Drupal core » Documentation
Version: 4.7.3 »
Component: user.module » Developer Guide
Jax’s picture

Category: task » bug

There is something missing in the patch. I was trying to update my birthday module to 4.7 and noticed somthing weird.

In hook_user I need to update 1 field and at the end I do

$edit['birthday'] = NULL;

like instructed in the documentation. But afterwards the user_save() overwrites my value. A workaround was to do:

unset($edit['birthday']);

But that is not what the documentation says.

So a solution would be to change user_save() to:

    foreach ($array as $key => $value) {
      if ($key == 'pass' && !empty($value)) {
        $query .= "$key = '%s', ";
        $v[] = md5($value);
      }
      else if ((substr($key, 0, 4) !== 'auth') && ($key != 'pass')) {
//        if (in_array($key, $user_fields)) {        >>> This is the line that changes
        if ($value !== NULL && in_array($key, $user_fields)) {		
          // Save standard fields
          $query .= "$key = '%s', ";
          $v[] = $value;
        }

So please explain if I should use unset or if the user.module should be patched? Or should the custom user fields be removed in the user_register_submit?

I know that usually extra user fields are added through profile but in this case it is not possible. Moreover, shouldn't it be possible to add user fields?

Jax’s picture

Project: Documentation » Drupal core
Version: » 4.7.3
Component: Developer Guide » user.module
Jax’s picture

FileSize
503 bytes

Patch implements my proposed solution. Maybe I should start a new thread for this issue?

Jax’s picture

Status: Active » Needs review
Darren Oh’s picture

Status: Needs review » Active

It would be best to open a new issue, since the original patch has already been committed. This issue was only re-opened to point out the need to document the change that had been made.

Jax’s picture

Project: Drupal core » Documentation
Version: 4.7.3 »
Component: user.module » Developer Guide
Category: bug » task

Ok. Created new issue and resetting the status of this one to what it was before I started fiddling with it.
http://drupal.org/node/85094

Darren Oh’s picture

Status: Active » Closed (fixed)

Patch committed. Documentation request is a duplicate of issue 77459.