Postponed on #3414370: Reset notice is showing up twice (from core and legal module) and don't disappear after password change
Problem/Motivation
When resetting your password, an E-mail is sent to you with a password reset link with an attached "password-reset-token". But, either if the user never accepted the legal terms (like in the tests, through programmatically creating a user "PasswordResetTest "=> "testPasswordReset()") or the "Ask to accept T&Cs on every login" setting is activated, the user has to accept the legal terms again, before he is able to reset his password.
Accepting the legal terms and pressing "Continue", will remove the "password-reset-token" and lead to the user not being able to properly reset their password.
Steps to reproduce
See Problem/Motivation.
Proposed resolution
- Keep the URL query intact after accepting the legal terms
- Test in "testPasswordReset()" that resetting the password actually works
- Split the "testPasswordReset()" test in three different tests:
- testPasswordResetWithoutLegalAccepted()
- testPasswordResetWithLegalAccepted()
- testPasswordResetLegalAcceptOnEveryLogin()
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork legal-3074688
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
johne commentedHere's a patch for dev
Comment #3
johne commentedThe previous patch doesn't apply cleanly on 8.x-1.0rc1 so I'm re-rolling for that.
Comment #4
jaydarnellTested and works as intended.
Comment #5
avpadernoThis seems a bug report. (Password reset links no longer work.)
Comment #6
avpadernoThe patch doesn't apply to the latest development snapshot.
Comment #7
mferanda commentedHi,
I had to stop using this module due to forgot password issues. Users are able to get into the website, but they're not able to change their password. It doesn't prompt for change after accepting and if they try to change, they of course need their previous password in order to change it.
Is there a newer version of this patch?
Comment #8
denisev commentedSimilar issue regarding one time login link https://www.drupal.org/project/legal/issues/2841132
Comment #9
johne commentedI've updated this patch for recent versions of drupal. This is for 8.x-1.0-rc1
Comment #10
johne commentedThis version is for 8.x-1.0-dev
Comment #11
avpadernoComment #13
avpadernoComment #14
mrinalini9 commentedComment #15
mrinalini9 commentedRerolled patch #10 as it failed to apply, please review.
Comment #17
nikitagupta commentedComment #18
nikitagupta commentedComment #19
jaydarnellA fix for this item needs to be committed. Left unchecked this issue makes the legal module completely unusable as it breaks absolutely critical site functionality (password reset requests).
Previous patches for this have provided optional configuration to skip terms and conditions on password reset requests, but it seems logical to me that the optional configuration is superfluous considering not enabling it means password resets are broken and there is already an option provided to display terms and conditions on user profile edit pages.
My suggestion would be to simply update the module to never display terms and conditions for password resets requests. I'll roll a patch for this momentarily.
Comment #20
jaydarnellA very minimal patch to simply skip T&C when one time login links have been used for password resets:
Comment #21
jaydarnellComment #22
mferanda commentedI've had this issue for a while and unfortunately disabled T&C... I re-enabled the requirement to test the patch.
Was still having the Forgot password issue before applying the patch... applied it.
Plain user login appears to still work fine with T&C
Forgot password - After clicking the link to log in, it immediately brought me to the password change screen. The simple skip code appears to work.
Comment #23
fjgarlin commentedWith the previous patch, it was still going through the hook in some occasions, so I mostly just moved the code to the beginning of the hook to bypass it straight away.
Comment #25
PhilippVerpoortJust to say that the patch in #23 worked for me using v.2.0.0 of the module.
I hope you'll get the failing tests resolved quickly and then get this whole patch committed!
Comment #26
ankithashettyHere is an attempt to fix the test failures in patch #23, kindly review.
Thank you!
Comment #28
ankithashettyPlease correct me if am wrong, since we are skipping T&C here when using a one-time login link for password resets, I think we can remove the following code from the test:
Thanks!
Comment #31
danielspeicher commentedThank you for the patch. I have opened a merge request, because I think this is the way to go now. I have also applied your patch https://www.drupal.org/files/issues/2021-06-01/3074688-28.patch.
The patch works, but not for all cases. We have a language based page and the method
Drupal::request()->getPathInfo()returns something like/en/user/reset/2356/1644301971/tKWfVzXsUCKSiZJ4rhwMGYtaE7ezaRxppTPri_QnEH8. So the check, if it is a one time link, does not work. I changed that tostr_contains( \Drupal::request()->getPathInfo(),'/user/reset/'). Furthermore, I have removed the deprecated code in the test class.Important note :
Now we skip the legal terms and a user can log in without confirmation. This is definitely not what we want, so make sure that in the legal configuration the following setting is checked:
By that option the user have to confirm, when setting or changing the password.
Comment #33
danielspeicher commentedWe just updated our last merge request. Now, the module can handle password reset links without any leaks. You have to confirm the terms and get redirected to the user edit form to set or change a password. So nobody can log in without confirmation. It does not depend on any configuration settings.
Comment #34
somersoft commentedThe above change in #32 only work for core >= 9.3.0. For those still below that, in legal/src/Form/LegalLogin.php:200 change
back to
to match core/modules/user/src/AccountForm.php:135
Comment #35
jukka792 commented#28 Worked for me, D9.3 version 2.0 PHP 8.1
and language set in the URL "language=en"
Comment #38
tobiasbI created a new MR for 3.0.x.
Comment #39
omd commentedThe patch in #28 no longer applies when using 3.0.1 and the older issue is still occurring - if there is a T&C change to accept when a user also needs to do a password reset, this user will see "You are not authorized to access this page. " and the logs will show:
Path: /legal_accept?destination=/user/6393/edit&token=Y4TDAQZgW2GfBznyr3WLYHSzLF-7cHrU6OmrNRC6SuQ. Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException: in Drupal\Core\Routing\AccessAwareRouter->checkAccess() (line 121 of /var/www/html/drupal/web/core/lib/Drupal/Core/Routing/AccessAwareRouter.php).
Comment #40
omd commentedCurious though, I have been unable to reproduce this now, with different users. Maybe was a browser cache issue. Fresh browser, fresh user and i am able to reset the password and accept a new T&C.
Comment #41
ron collins commentedI've created a patch from the MR in #37 for Legal 3.0.1
Comment #42
anybodyCould someone, who is running into this issue, please add clear steps to the issue summary how to reproduce this in 3.0.x?
In which cases does this happen?
Does the switch in #31 affect this issue?
This should definitely be fixed and I think it's major if it still happens as described, but the issue summary is poor for reproduction.
Further report: #3326543: Password reset not working
Comment #43
grevil commentedI updated the issue summary to provide clear steps on how to reproduce this issue in 3.0.x.
It doesn't, but it generally seems, that this issue is not as bad as before, since when the user already accepted the legal terms, the issue won't come up.
Comment #44
grevil commented"3074688-password-reset-links-3.0.x" doesn't look finished yet. I can't find the time to have a detailed look into this, but I can tell, that this still needs work.
The old MR 7 can be closed I guess.
Comment #45
grevil commentedComment #46
grevil commentedComment #47
grevil commentedOk, I didn't think about changing legal terms, which need to get accepted once again. As this is quite common and will trigger this issue, I'll set this issue to major.
Comment #48
grevil commentedOk, I added "testPasswordResetWithoutLegalAccepted()", "testPasswordResetWithLegalAccepted()" and generally refactored the tests in #3414370: Reset notice is showing up twice (from core and legal module) and don't disappear after password change, because that issue is also indirectly affected by the problem described inside this issue.
Test-wise, we should wait for that issue to get merged, before we touch the tests here.
Comment #49
grevil commentedAlright, the provided patch works great!
Let's wait for #3414370: Reset notice is showing up twice (from core and legal module) and don't disappear after password change to get merged, so we can start with the remaining test and check if this MR introduces any regressions.
POSTPONED on #3414370: Reset notice is showing up twice (from core and legal module) and don't disappear after password change
Comment #51
anybodyComment #52
anybody@Grevil I guess you mean MR!11?
Comment #53
grevil commented@Anybody when exactly?
?
I meant MR 7 there.
Comment #54
robert castelo commented@Grevil not sure I understand this issue....manually testing I wasn't able to reproduce the issue at all.
Am I right in thinking that this is now just an issue with automated tests?
Comment #55
anybody@Ron Collins which version of the module did you test? Did you test with any other patches / MR's applied?
I don't think so. This issue exists in 3.0.x. We'll add clear steps to reproduce this. Like in #3414370: Reset notice is showing up twice (from core and legal module) and don't disappear after password change we have to ensure we describe all possible paths and have tests for them.
Comment #56
grevil commented@Robert Castelo, I can provide more specific steps to reproduce if needed!
Steps to reproduce:
Comment #57
ron collins commented@anybody 3.0.1 is installed.
There was one other patch applied: https://www.drupal.org/files/issues/2023-01-23/3283807-8-deprecated-func...
Comment #59
grevil commented@Robert Castelo any reason this was merged without any status change at all?
This issue was still missing test implementations. Also, no credits were given yet. @danielspeicher, @jurgenhaas and others contributed quite a bit here!
I'll create a follow-up issue for fixing / adding the missing tests.
Comment #60
grevil commentedComment #61
robert castelo commented@Grevil I've merged but still need to make some changes before I consider this issue resolved, which I'm currently working on.
I've given attribution when I merged, maybe that commit is still local and I need to push to origin.
Commit:
e99a8547c3f9d5cee4845be049b7f2acabec9274 [e99a854]
Issue #3074688 by johne, jurgenhaas, ankithashetty, danielspeicher, tobiasb, Grevil, JayDarnell, Ron Collins, mrinalini9, fjgarlin: [PP-1] Password can not be reset, when user hasn't accepted the legal terms yet
Comment #62
grevil commentedOk.
Credit through commit isn't enough anymore, you need to additionally credit users through the "Credit & commiting" section when adding a new comment in the issue.
Comment #63
grevil commented@Robert Castelo I finished the tests in #3447348: Fix and add remaining test now.
EDIT: Ok, they still currently fail. Needs some further work. No more noise here.
Comment #64
robert castelo commentedComment #65
robert castelo commented@Grevil I fixed the tests and also an issue with the one time login message not appearing on the password reset page.
I already credited everyone who contributed code in the "Credit & committing" section when merging the issue through the issue page, let me know if there's anything else that needs to be done to give credit.
Comment #66
grevil commentedEveryone seems to be properly credited now, thanks! :)
Comment #68
danielspeicher commented