From d23fba451ee0d6e16b32c997f92ced1430b6e737 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 27 Jul 2016 01:04:29 -0300 Subject: [PATCH] Ivan - Add smtp settings [skip ci] --- server/controllers/system/init-settings.php | 7 ++++++- server/libs/MailSender.php | 22 +++++++++------------ server/models/MailTemplate.php | 2 +- server/models/Setting.php | 4 +++- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/server/controllers/system/init-settings.php b/server/controllers/system/init-settings.php index e1a3bbbe..578791b5 100644 --- a/server/controllers/system/init-settings.php +++ b/server/controllers/system/init-settings.php @@ -23,7 +23,12 @@ class InitSettingsController extends Controller { private function storeGlobalSettings() { $this->storeSettings([ - 'language' => 'en' + 'language' => 'en', + 'no-reply-email' => 'noreply@opensupports.com', + 'smtp-host' => 'localhost', + 'smtp-port' => 7070, + 'smtp-user' => '', + 'smtp-pass' => '', ]); } diff --git a/server/libs/MailSender.php b/server/libs/MailSender.php index e419f07f..869b97c2 100644 --- a/server/libs/MailSender.php +++ b/server/libs/MailSender.php @@ -3,15 +3,13 @@ class MailSender { private $mailOptions = []; - //TODO: Add real initial options when Settings class is available public function __construct() { - $this->mailOptions['from'] = 'noreply@opensupports.com'; + $this->mailOptions['from'] = Setting::getSetting('no-reply-email'); - //SMTP Options - $this->mailOptions['smtp_host'] = 'localhost'; - $this->mailOptions['smtp_port'] = 7070; - $this->mailOptions['smtp_user'] = ''; - $this->mailOptions['smtp_pass'] = ''; + $this->mailOptions['smtp-host'] = Setting::getSetting('smtp-host'); + $this->mailOptions['smtp-port'] = Setting::getSetting('smtp-host'); + $this->mailOptions['smtp-user'] = Setting::getSetting('smtp-host'); + $this->mailOptions['smtp-pass'] = Setting::getSetting('smtp-host'); } public function setTemplate($type, $config) { @@ -29,14 +27,12 @@ class MailSender { $mailer->Subject = $this->mailOptions['subject']; $mailer->Body = $this->mailOptions['body']; - //$mailer->SMTPDebug = 3; $mailer->isSMTP(); $mailer->SMTPAuth = true; - $mailer->Host = $this->mailOptions['smtp_host']; - $mailer->Port = $this->mailOptions['smtp_port']; - $mailer->Username = $this->mailOptions['smtp_user']; - $mailer->Password = $this->mailOptions['smtp_pass']; - //$mailer->SMTPSecure = "tls"; + $mailer->Host = $this->mailOptions['smtp-host']; + $mailer->Port = $this->mailOptions['smtp-port']; + $mailer->Username = $this->mailOptions['smtp-user']; + $mailer->Password = $this->mailOptions['smtp-pass']; $mailer->Timeout = 1000; if ($mailer->smtpConnect()) { diff --git a/server/models/MailTemplate.php b/server/models/MailTemplate.php index 2d031e91..14bf7fa0 100644 --- a/server/models/MailTemplate.php +++ b/server/models/MailTemplate.php @@ -12,7 +12,7 @@ class MailTemplate extends DataStore { $bean = RedBean::findOne(MailTemplate::TABLE, 'type = :type AND language = :language', array( ':type' => $type, - ':language' => $globalLanguage->value + ':language' => $globalLanguage )); return ($bean) ? new MailTemplate($bean) : null; diff --git a/server/models/Setting.php b/server/models/Setting.php index 0df2404b..c6015d8d 100644 --- a/server/models/Setting.php +++ b/server/models/Setting.php @@ -4,7 +4,9 @@ class Setting extends DataStore { const TABLE = 'setting'; public static function getSetting($name) { - return parent::getDataStore($name, 'name'); + $dataStore = parent::getDataStore($name, 'name'); + + return ($dataStore !== null) ? $dataStore->value : null; } public static function getProps() {