From a0c9f9f90c819998fe88e687342415c97f322d48 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 19 Jul 2019 07:33:54 -0700 Subject: [PATCH] Allow installs to customize mail body guidance in the "Email Login" and "Set Password" emails Summary: Depends on D20662. Ref T13343. Installs may reasonably want to change the guidance users receive in "Email Login"/"Forgot Password" email. (In an upcoming change I plan to supply a piece of default guidance, but Auth Messages need a few tweaks for this.) There's probably little reason to provide guidance on the "Set Password" flow, but any guidance one might issue on the "Email Login" flow probably doesn't make sense on the "Set Password" flow, so I've included it mostly to make it clear that this is a different flow from a user perspective. Test Plan: - Set custom "Email Login" and "Set Password" messages. - Generated "Email Login" mail by using the "Login via email" link on the login screen. - Generated "Set Password" email by trying to set a password on an account with no password yet. - Saw my custom messages in the resulting mail bodies. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13343 Differential Revision: https://secure.phabricator.com/D20663 --- src/__phutil_library_map__.php | 4 +++ .../PhabricatorAuthEmailLoginMessageType.php | 18 +++++++++++++ ...ricatorAuthEmailSetPasswordMessageType.php | 18 +++++++++++++ .../message/PhabricatorAuthMessageType.php | 1 + .../PhabricatorAuthWelcomeMailMessageType.php | 2 +- .../auth/storage/PhabricatorAuthMessage.php | 2 +- .../PhabricatorPeopleEmailLoginMailEngine.php | 25 ++++++++++++++++--- 7 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 src/applications/auth/message/PhabricatorAuthEmailLoginMessageType.php create mode 100644 src/applications/auth/message/PhabricatorAuthEmailSetPasswordMessageType.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index dc94bfd726..93dc753ded 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2265,6 +2265,8 @@ phutil_register_library_map(array( 'PhabricatorAuthDisableController' => 'applications/auth/controller/config/PhabricatorAuthDisableController.php', 'PhabricatorAuthDowngradeSessionController' => 'applications/auth/controller/PhabricatorAuthDowngradeSessionController.php', 'PhabricatorAuthEditController' => 'applications/auth/controller/config/PhabricatorAuthEditController.php', + 'PhabricatorAuthEmailLoginMessageType' => 'applications/auth/message/PhabricatorAuthEmailLoginMessageType.php', + 'PhabricatorAuthEmailSetPasswordMessageType' => 'applications/auth/message/PhabricatorAuthEmailSetPasswordMessageType.php', 'PhabricatorAuthFactor' => 'applications/auth/factor/PhabricatorAuthFactor.php', 'PhabricatorAuthFactorConfig' => 'applications/auth/storage/PhabricatorAuthFactorConfig.php', 'PhabricatorAuthFactorConfigQuery' => 'applications/auth/query/PhabricatorAuthFactorConfigQuery.php', @@ -8220,6 +8222,8 @@ phutil_register_library_map(array( 'PhabricatorAuthDisableController' => 'PhabricatorAuthProviderConfigController', 'PhabricatorAuthDowngradeSessionController' => 'PhabricatorAuthController', 'PhabricatorAuthEditController' => 'PhabricatorAuthProviderConfigController', + 'PhabricatorAuthEmailLoginMessageType' => 'PhabricatorAuthMessageType', + 'PhabricatorAuthEmailSetPasswordMessageType' => 'PhabricatorAuthMessageType', 'PhabricatorAuthFactor' => 'Phobject', 'PhabricatorAuthFactorConfig' => array( 'PhabricatorAuthDAO', diff --git a/src/applications/auth/message/PhabricatorAuthEmailLoginMessageType.php b/src/applications/auth/message/PhabricatorAuthEmailLoginMessageType.php new file mode 100644 index 0000000000..a866dfa9e2 --- /dev/null +++ b/src/applications/auth/message/PhabricatorAuthEmailLoginMessageType.php @@ -0,0 +1,18 @@ +getID()); + return urisprintf('/auth/message/%s/', $this->getID()); } public function attachMessageType(PhabricatorAuthMessageType $type) { diff --git a/src/applications/people/mail/PhabricatorPeopleEmailLoginMailEngine.php b/src/applications/people/mail/PhabricatorPeopleEmailLoginMailEngine.php index 504d6c01cf..325309c71b 100644 --- a/src/applications/people/mail/PhabricatorPeopleEmailLoginMailEngine.php +++ b/src/applications/people/mail/PhabricatorPeopleEmailLoginMailEngine.php @@ -43,19 +43,34 @@ final class PhabricatorPeopleEmailLoginMailEngine $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); $have_passwords = $this->isPasswordAuthEnabled(); + $body = array(); + + if ($is_set_password) { + $message_key = PhabricatorAuthEmailSetPasswordMessageType::MESSAGEKEY; + } else { + $message_key = PhabricatorAuthEmailLoginMessageType::MESSAGEKEY; + } + + $message_body = PhabricatorAuthMessage::loadMessageText( + $recipient, + $message_key); + if (strlen($message_body)) { + $body[] = $this->newRemarkupText($message_body); + } + if ($have_passwords) { if ($is_set_password) { - $body = pht( + $body[] = pht( 'You can use this link to set a password on your account:'. "\n\n %s\n", $login_uri); } else if ($is_serious) { - $body = pht( + $body[] = pht( "You can use this link to reset your Phabricator password:". "\n\n %s\n", $login_uri); } else { - $body = pht( + $body[] = pht( "Condolences on forgetting your password. You can use this ". "link to reset it:\n\n". " %s\n\n". @@ -68,7 +83,7 @@ final class PhabricatorPeopleEmailLoginMailEngine } } else { - $body = pht( + $body[] = pht( "You can use this login link to regain access to your Phabricator ". "account:". "\n\n". @@ -76,6 +91,8 @@ final class PhabricatorPeopleEmailLoginMailEngine $login_uri); } + $body = implode("\n\n", $body); + return id(new PhabricatorMetaMTAMail()) ->setSubject($subject) ->setBody($body);