Problem/Motivation
After 5 fail login attempts, the website got a fatal PHP error said 'TypeError: Argument 4 passed to Drupal\tfa\TfaContext::__construct() must implement interface Drupal\user\UserInterface, null given'
Steps to reproduce
1. Enable and set up the TFA for user login.
2. Try login with any wrong password for 6 times (Default flood threshold is 5)
3. A white screen show up said' The website encountered an unexpected error. Please try again later.'
Proposed resolution
The logic behind Drupal user login form is changed since Drupal 9.
See the difference from the source code in D9:
https://git.drupalcode.org/project/drupal/-/blob/9.2.x/core/modules/user...
In D8:
https://git.drupalcode.org/project/drupal/-/blob/8.9.x/core/modules/user...
Therefore, we need to add following codes into /src/Form/TfaLoginForm.php
// The user ID must not be NULL.
if (empty($uid = $form_state->get('uid'))) {
return;
}
Remaining tasks
Since the logic is different between D8 and D9, we need to rewrite the TFA user login form to reflect all changes since Drupal 9.
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Comment | File | Size | Author |
---|---|---|---|
#2 | tfa-3205297-2.patch | 629 bytes | Mingsong |
Issue fork tfa-3205297
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
MingsongPatch to fix this issue.
Comment #4
MingsongComment #6
jcnventura CreditAttribution: jcnventura at 1xINTERNET commentedThanks for the code. Even when whoever did it in core decided to make it clever and horrible to read by doing an if (var = value) {}.
All the programming best practice standards I've read recommend against that, but I understand why you decided to 'do as core does'.
Comment #7
MingsongAgree, It is very confusing to write code in this way.
Comment #8
MingsongComment #10
Anonymous (not verified) CreditAttribution: Anonymous commentedWhen Applying patches from the issue :User login page broken this modules gets broken as the parent constructor needs BareHtmlPageRendererInterface. Solution is to update the constructor as follows
Also add
$container->get('bare_html_page_renderer')
at the end of the create function.