diff options
author | Ben Burgess <88810029+bx80@users.noreply.github.com> | 2022-06-21 11:55:43 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-21 11:55:43 +0300 |
commit | 4d67df45bef94d664a14b6e707d1b12ff132d53f (patch) | |
tree | e703c80b6dc2873704cf079cbecfd811921d6959 | |
parent | 6a6dce9c9c36e35a6822b7c4e05def5b84f00d07 (diff) |
Improve password reset email formatting (#19357)
* Improve password reset email plain text and html bodies
* Add <a> tag for reset link
* fix tests
* built vue files
Co-authored-by: sgiehl <stefan@matomo.org>
Co-authored-by: sgiehl <sgiehl@users.noreply.github.com>
-rw-r--r-- | plugins/Login/Emails/PasswordResetEmail.php | 27 | ||||
-rw-r--r-- | plugins/Login/tests/Integration/PasswordResetterTest.php | 2 |
2 files changed, 25 insertions, 4 deletions
diff --git a/plugins/Login/Emails/PasswordResetEmail.php b/plugins/Login/Emails/PasswordResetEmail.php index bdded77c45..dbbff22b24 100644 --- a/plugins/Login/Emails/PasswordResetEmail.php +++ b/plugins/Login/Emails/PasswordResetEmail.php @@ -49,7 +49,8 @@ class PasswordResetEmail extends Mail $this->setSubject($this->getDefaultSubject()); $this->addReplyTo($replytoEmailAddress, $replytoEmailName); - $this->setWrappedHtmlBody($this->getDefaultBodyText()); + $this->setWrappedHtmlBody($this->getHTMLBody()); + $this->setBodyText($this->getDefaultBodyText()); } private function getDefaultSubject() @@ -57,12 +58,32 @@ class PasswordResetEmail extends Mail return Piwik::translate('Login_MailTopicPasswordChange'); } - private function getDefaultBodyText() + /** + * Get the translated plain text email body with the reset link + * + * @return string + */ + private function getDefaultBodyText() : string + { + return Piwik::translate('Login_MailPasswordChangeBody2', + [Common::sanitizeInputValue($this->login), Common::sanitizeInputValue($this->ip), Common::sanitizeInputValue($this->resetUrl)]); + } + + /** + * Create the HTML email body from the plain text body + * + * @return string + */ + private function getHTMLBody() : string { return '<p>' . str_replace( "\n\n", "</p><p>", - Piwik::translate('Login_MailPasswordChangeBody2', [Common::sanitizeInputValue($this->login), Common::sanitizeInputValue($this->ip), Common::sanitizeInputValue($this->resetUrl)]) + Piwik::translate('Login_MailPasswordChangeBody2', + [Common::sanitizeInputValue($this->login), + Common::sanitizeInputValue($this->ip), + '<p style="word-break: break-all"><a href="'.Common::sanitizeInputValue($this->resetUrl).'">'. + Common::sanitizeInputValue($this->resetUrl).'</a></p>']) ) . "</p>"; } }
\ No newline at end of file diff --git a/plugins/Login/tests/Integration/PasswordResetterTest.php b/plugins/Login/tests/Integration/PasswordResetterTest.php index b6014aecff..632f5b7618 100644 --- a/plugins/Login/tests/Integration/PasswordResetterTest.php +++ b/plugins/Login/tests/Integration/PasswordResetterTest.php @@ -195,7 +195,7 @@ class PasswordResetterTest extends IntegrationTestCase ['Test.Mail.send', \DI\value(function (PHPMailer $mail) { $body = $mail->createBody(); $body = preg_replace("/=[\r\n]+/", '', $body); - preg_match('/resetToken=[\s]*3D([a-zA-Z0-9=\s]+)<\/p>/', $body, $matches); + preg_match('/resetToken=[\s]*3D([a-zA-Z0-9=\s]+)"/', $body, $matches); if (!empty($matches[1])) { $capturedToken = $matches[1]; $capturedToken = preg_replace('/=\s*/', '', $capturedToken); |