Problem/Motivation
I've found there is a problem with one-time login link generated during registration or password reset request, that leads to user/%/edit form. If there is a file field and user uploads an file by clicking "Upload" button form is submitted through AJAX and one-time login expires. So as soon as user fills new password and submits full form an errors occurs "Your current password is missing or incorrect; it's required to change the Password.".
Steps to reproduce:
- Set "Who can register accounts" to "Visitors, but administrator approval is required" on Account Settings page
- Check "Require e-mail verification when a visitor creates an account." on Account Settings page
- Add a file or image field to account entity
- Create a new user and activate it or request a password reset
- Make sure you're logged out, then use one-time login link received in email
- Select an file/image and click "Upload"
- Fill new password and submit form
Proposed resolution
It's only a workaround but unchecking "Require e-mail verification when a visitor creates an account." on Account Settings page solves the problem for registration process. It won't help with Reset Password request.
Remaining tasks
I think it needs reviewing cause this completly breaks form after uploading a file. I'll try to fix this as soon as I have time.
Beta phase evaluation
| Issue category | Bug |
|---|---|
| Unfrozen changes | Unfrozen because it is a bug that exists in Drupal 7 as well |
| Comment | File | Size | Author |
|---|---|---|---|
| #45 | 1858486-same_as_patch25_for_comment45-1858486-45.patch | 3.94 KB | joseph.olstad |
| #25 | 1858486-25.patch | 3.94 KB | idebr |
| #25 | 1858486-25.fail_.patch | 2.38 KB | idebr |
| #20 | 1858486-20.patch | 3.04 KB | idebr |
| #20 | interdiff-20-17.txt | 3.01 KB | idebr |
Comments
Comment #1
trawekp-1 commentedI think I've found a solution. The real problem lies in handling Account Form rebuild. The form needs a 'pass-reset-token' GET variable to skip Current Password validation so every AJAX rebuild breaks this.
I have figured out that to fix it we need to store pass-reset-token as hidden value inside the form and then retrieve it when $_GET['pass-reset-token'] is not set.
I know that all the submitted values should be fetched from $form_state['values'] but it is necessary to get stored token from $form_state['input'] because AJAX rebuilds are usually called by buttons with #limit_validation_errors.
Anyway I am not sure if this is safe, what I know is that token is public so storing it as hidden value is not a problem.
Here's the patch:
Comment #2
Johnny vd Laar commentedThis fix seems to work. Very odd that nobody found this problem before as it seems like a common use case.
Comment #3
Johnny vd Laar commentedIf you don't want to patch your drupal core then you can do this in a form alter:
Comment #4
David_Rothstein commentedThis is reproducible in Drupal 8 also.
Maybe it would be better to store the token in $form_state directly the first time it's found, rather than passing it back and forth to the browser?
Comment #5
David_Rothstein commentedSomething like the attached, maybe... Seems to work based on some quick testing.
Comment #6
trawekp-1 commentedSeems fine to me
Comment #7
rob230 commentedIt is surprising that this bug with Drupal 7 core has not been reported more. I suppose not many people use AJAX on the user profile / registration forms, but it is completely site breaking for one of my sites. Nobody can register at all.
I fixed this simply by using the nocurrent_pass module but really I think this should be fixed in 7 as well as 8.
Comment #8
David_Rothstein commentedYeah, I'm a bit surprised too.
Once the above patch is reviewed and committed to Drupal 8, it can be backported to Drupal 7 and fixed there also.
Comment #9
eldargp commentedHi there, I am experiencing this issue with my registration form since I am using an extra image field with upload Ajax button. Are any of this two patches working with drupal core 7.20? tried #1 but failed when submitting form SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
thanks
Comment #10
marcingy commentedIssues are fixed in d8 first
Comment #11
super_romeo commentedand what about D7 commit?
Comment #12
marcingy commentedIt gets committed once it is fixed in D8.
Comment #13
mrharolda commentedHere's a re-rolled patch for D7 that fixes some code and comment style.
Comment #14
jhedstromComment #15
idebr commentedComment #17
idebr commentedComment #18
jhedstromWould it be possible to add a test here?
The fix itself looks solid to me, although I haven't confirmed the fix manually.
I've updated the issue summary to include a beta phase evaluation.
Comment #19
jhedstromComment #20
idebr commentedI added a test and updated the code slightly.
Comment #22
jhedstromThanks for the test! I think this is good to go.
Comment #23
alexpottCommitted 29f441d and pushed to 8.0.x. Thanks!
Thanks for adding the beta evaluation to the issue summary.
Comment #25
idebr commentedPorted the patch to D7.
Comment #27
leahtard commentedI ran into this same issue and thankfully found this patch. While this patch got rid of the ugly error for me, it didn't completely resolve my issue. On my user profile form, I have a multi value text field that accepts unlimited values. This initially presents itself as one text field with an "Add Another Item" button. Now, with this patch in place, when I click the "Add Another Item" no second text field appears -- I get a 500 Internal Server Error in my console log.
If additional information is needed from my end, please request :)
Cheers, Leah
Comment #28
l0keThank's for backport to D7.
Didn't test it with multi value text field but worked fine for "Address Field".
+1
Comment #32
greatmatter commentedI'm excited to see this actually get released.
Comment #33
alesr commentedI reviewed the patch in #25.
It basically does one simple thing.
It stores the check
in $form_state['user_pass_reset'] instead of using $pass_reset variable and by doing that it prevents the fail after form submission which is caused by any AJAX related form submit like user photo upload etc.
RTBC and would be nice to get it in the next D7 release too.
Comment #34
stefan.r commentedComment #35
stefan.r commentedAt first sight this looks good -- the D7 and D8 code are identical and the tests look OK as well.
Comment #36
David_Rothstein commentedThe tests look good to me also. The original patch was mine, so ideally someone else would commit it.
However, has anyone looked into #27? We need to make sure there isn't a regression there.
One other small thing (could be fixed on commit):
Should be "Ajax".
Comment #37
fabianx commentedThanks for all the work on this, but given #27 I think this needs more review (and time).
Also while I understand that it can be a nuisance and is for sure a bug, it is rightly only normal priority as it is not that likely that a user first uploads a new file before proceeding to reset their password.
Obviously for password confirmation, this is way more likely.
Therefore setting back to needs review and not getting this in for 7.51 (but hopefully for 7.52).
--
Actionable item:
Try to re-create #27 on vanilla Drupal.
Comment #38
mxr576We run into this issue therefore having address field (Company select) on profile forms.
I've tried to reproduce #27 based on the infos we had, but everything worked fine.
Comment #39
weri commentedWe had this problem with D7 as we attached a form (field_attach_form) with an address field to the user form. The patch #25 solved the problem and we noticed no other problems with this patch.
Comment #42
stefan.r commentedComment #43
joseph.olstadD7 solution is identical, ready.
Fabianx can this get into this month's release?
Comment #44
David_Rothstein commentedSeems like with the additional testing that happened above, this is probably ready to go in.
#27 really doesn't sound related, and actually reading that again I'm not sure if it's even implying that this patch caused the problem; maybe it was a preexisting problem on that site that this patch just didn't happen to solve?
Comment #45
joseph.olstadI'd say this is ready to go, all reports after #27 are saying this is good.
and the fact that it's already in D8 verbatim.
here's the patch again from 25, just for running the tests.
Comment #46
stefan.r commentedLooks good.
Comment #48
stefan.r commentedCommitted and pushed to 7.x, thanks!