When I try to disable TFA for an account, I get a WSOD with an ugly error message:

GuzzleHttp\Exception\ClientException: Client error: `POST https://api.sendgrid.com/api/mail.send.json` resulted in a `400 Bad Request` response: {"errors":["Missing email body"],"message":"error"} in GuzzleHttp\Exception\RequestException::create() (line 113 of /app/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php).

I am using SendGrid to send mail, which is why Guzzle gets involved. The symptom might be less drastic if we are relying on the default e-mail handler, but I am pretty sure that it still does not work. The code comment (in src/Form/BasicDisable.php) agrees with me:

    // @todo Not working, not sure why though.
    // E-mail account to inform user that it has been disabled.
    $params = ['account' => $account];
    \Drupal::service('plugin.manager.mail')->mail('tfa', 'tfa_disabled_configuration', $account->getEmail(), $account->getPreferredLangcode(), $params);

It looks to me as though the problem is that the module does not implement hook_mail().

Comments

benjifisher created an issue. See original summary.

benjifisher’s picture

Assigned: Unassigned » benjifisher

I am working on this now.

benjifisher’s picture

Assigned: benjifisher » Unassigned
Status: Active » Needs review
StatusFileSize
new3.17 KB

It looks as though the @todo comment was added in Commit 122059f0, and that a lot of code was copied over from the tfa_basic module, but not tfa_basic_mail(). This patch is based on that function.

The API documentation for hook_mail() uses strtr() instead of t(). Maybe hook_mail() is invoked in a partially bootstrapped environment? I am using t(), but I have not tested on a multilingual site.

This patch also un-comments and updates the lines that send an e-mail confirmation when setting up an account.

While testing this, I once received two copies of the e-mail when setting up TFA. Maybe that is an unreproducible glitch, but please keep an eye out for this when testing yourself.

daggerhart’s picture

StatusFileSize
new4.8 KB
new1.49 KB

This applies cleanly and works as written, but it brings up some UX issues.

  1. Emails aren't configurable by the site admin. Not a big problem, I'll create another issue to address this.
  2. I receive the same email twice if I have recovery codes enabled. This is a bit more nuanced.

Concerning #2: This is happening because the recovery codes are currently a "fallback" plugin. The concept will be removed in #2924691: Remove fallback plugins, make recovery code concept into validation & setup plugins, but for now we probably need to make sure that the current plugin is not a fallback plugin before sending the email.

Attached is a patch that does a bit of work to make sure the current plugin is not a fallback plugin. I didn't use DI because this is temporary (hopefully). And the hacky-looking str_replace to find the validation plugin id is because the way setup plugins are currently defined is a hardcoded expectation of validation_plugin_id . "_setup"

Thoughts?

Status: Needs review » Needs work

The last submitted patch, 4: 2931147-4.patch, failed testing. View results

daggerhart’s picture

Status: Needs work » Needs review

wow, my last patch was terrible. restoring #3. The interdiff is correct, but something went wrong w/ the actual patch roll.

daggerhart’s picture

StatusFileSize
new3.98 KB
new1.49 KB

Trying this patch thing again.

benjifisher’s picture

StatusFileSize
new3.9 KB
new1.47 KB
new1.2 KB

I was wondering about the double e-mail. Usually I skip the recovery codes, sometimes I do not. That is why I only saw the duplicate once.

Here is a variant of your patch. The idea is to make it easier to update after #2924691: Remove fallback plugins, make recovery code concept into validation & setup plugins goes in.

I have attached interdiffs to compare with the patches from Comment #3 and Comment #6.

I tested this patch locally. I get only one confirmation message, but I see the message twice in the logs, as expected.

daggerhart’s picture

Status: Needs review » Reviewed & tested by the community
Related issues: +#2932170: Create a UI for site admins to configure the emails sent by tfa module

This looks even better, thank you! RTBC, and adding reference to the new UI task for these emails.

  • nerdstein committed bfc5e3c on 8.x-1.x authored by benjifisher
    Issue #2931147 by benjifisher, daggerhart: Error when disabling TFA for...
nerdstein’s picture

Status: Reviewed & tested by the community » Fixed

The patch in #8 looks great - thanks for catching this. Merged.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.