From 8ca9264646b7b18378c4a5e3b0593f4a9b1ad510 Mon Sep 17 00:00:00 2001 From: "Kasper A. Svendsen" Date: Thu, 8 Oct 2015 11:19:32 +0200 Subject: [PATCH] added feature to config wheter to use html email or text email --- config/goalioforgotpassword.global.php.dist | 7 +++++++ .../Options/ForgotOptionsInterface.php | 2 ++ .../Options/ModuleOptions.php | 21 +++++++++++++++++++ src/GoalioForgotPassword/Service/Password.php | 12 ++++++++++- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/config/goalioforgotpassword.global.php.dist b/config/goalioforgotpassword.global.php.dist index dd86a81..ebc9813 100644 --- a/config/goalioforgotpassword.global.php.dist +++ b/config/goalioforgotpassword.global.php.dist @@ -66,6 +66,13 @@ $settings = array( */ //'validate_existing_record' => true + + /** + * Email format + * Valid: html or text + */ + //'email_format' => 'text' + /** * End of GoalioForgotPassword configuration */ diff --git a/src/GoalioForgotPassword/Options/ForgotOptionsInterface.php b/src/GoalioForgotPassword/Options/ForgotOptionsInterface.php index 32f71d0..682c7d8 100644 --- a/src/GoalioForgotPassword/Options/ForgotOptionsInterface.php +++ b/src/GoalioForgotPassword/Options/ForgotOptionsInterface.php @@ -12,4 +12,6 @@ public function setResetEmailSubjectLine($subject); public function getResetEmailSubjectLine(); public function setResetEmailTemplate($template); public function getResetEmailTemplate(); + public function setEmailFormat($emailFormat); + public function getEmailFormat(); } diff --git a/src/GoalioForgotPassword/Options/ModuleOptions.php b/src/GoalioForgotPassword/Options/ModuleOptions.php index e40448a..bd77cdf 100644 --- a/src/GoalioForgotPassword/Options/ModuleOptions.php +++ b/src/GoalioForgotPassword/Options/ModuleOptions.php @@ -36,6 +36,11 @@ class ModuleOptions extends AbstractOptions implements * @var int */ protected $resetExpire = 86400; + + /** + * @var string + */ + protected $emailFormat = 'text'; /** * @var bool @@ -118,4 +123,20 @@ public function setResetExpire($resetExpire) { public function getResetExpire() { return $this->resetExpire; } + + /** + * @return string + */ + public function getEmailFormat() { + return $this->emailFormat; + } + + /** + * @param string $emailFormat + * @return $this + */ + public function setEmailFormat($emailFormat) { + $this->emailFormat = $emailFormat; + return $this; + } } diff --git a/src/GoalioForgotPassword/Service/Password.php b/src/GoalioForgotPassword/Service/Password.php index 05154d9..914d60b 100644 --- a/src/GoalioForgotPassword/Service/Password.php +++ b/src/GoalioForgotPassword/Service/Password.php @@ -2,6 +2,7 @@ namespace GoalioForgotPassword\Service; +use GoalioMailService\Mail\Service\Message; use Zend\Mail\Transport\TransportInterface; use ZfcUser\Options\PasswordOptionsInterface; @@ -77,13 +78,22 @@ public function sendProcessForgotRequest($userId, $email) public function sendForgotEmailMessage($to, $model) { + /** @var Message $mailService */ $mailService = $this->getServiceManager()->get('goaliomailservice_message'); $from = $this->getOptions()->getEmailFromAddress(); $subject = $this->getOptions()->getResetEmailSubjectLine(); $template = $this->getOptions()->getResetEmailTemplate(); - $message = $mailService->createTextMessage($from, $to, $subject, $template, array('record' => $model)); + switch($this->getOptions()->getEmailFormat()) { + case "html": + $message = $mailService->createHtmlMessage($from, $to, $subject, $template, array('record' => $model)); + break; + case "text": + default: + $message = $mailService->createTextMessage($from, $to, $subject, $template, array('record' => $model)); + break; + } $mailService->send($message); }