diff options
-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); |