summaryrefslogtreecommitdiffstats
path: root/settings/Controller/MailSettingsController.php
diff options
context:
space:
mode:
Diffstat (limited to 'settings/Controller/MailSettingsController.php')
-rw-r--r--settings/Controller/MailSettingsController.php65
1 files changed, 27 insertions, 38 deletions
diff --git a/settings/Controller/MailSettingsController.php b/settings/Controller/MailSettingsController.php
index 8137b4da53c..ed742059665 100644
--- a/settings/Controller/MailSettingsController.php
+++ b/settings/Controller/MailSettingsController.php
@@ -1,5 +1,6 @@
<?php
/**
+ * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Joas Schilling <coding@schilljs.com>
@@ -25,6 +26,8 @@
namespace OC\Settings\Controller;
use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
use OCP\IL10N;
use OCP\IConfig;
@@ -84,7 +87,7 @@ class MailSettingsController extends Controller {
* @param string $mail_smtpauthtype
* @param int $mail_smtpauth
* @param string $mail_smtpport
- * @return array
+ * @return DataResponse
*/
public function setMailSettings($mail_domain,
$mail_from_address,
@@ -109,12 +112,7 @@ class MailSettingsController extends Controller {
$this->config->setSystemValues($configs);
- return array('data' =>
- array('message' =>
- (string) $this->l10n->t('Saved')
- ),
- 'status' => 'success'
- );
+ return new DataResponse();
}
/**
@@ -124,62 +122,53 @@ class MailSettingsController extends Controller {
*
* @param string $mail_smtpname
* @param string $mail_smtppassword
- * @return array
+ * @return DataResponse
*/
public function storeCredentials($mail_smtpname, $mail_smtppassword) {
+ if ($mail_smtppassword === '********') {
+ return new DataResponse($this->l10n->t('Invalid SMTP password.'), Http::STATUS_BAD_REQUEST);
+ }
+
$this->config->setSystemValues([
'mail_smtpname' => $mail_smtpname,
'mail_smtppassword' => $mail_smtppassword,
]);
- return array('data' =>
- array('message' =>
- (string) $this->l10n->t('Saved')
- ),
- 'status' => 'success'
- );
+ return new DataResponse();
}
/**
* Send a mail to test the settings
- * @return array
+ * @return DataResponse
*/
public function sendTestMail() {
$email = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'email', '');
if (!empty($email)) {
try {
+ $displayName = $this->userSession->getUser()->getDisplayName();
+
+ $template = $this->mailer->createEMailTemplate();
+ $template->addHeader();
+ $template->addHeading($this->l10n->t('Well done, %s!', [$displayName]));
+ $template->addBodyText($this->l10n->t('If you received this email, the email configuration seems to be correct.'));
+ $template->addFooter();
+
$message = $this->mailer->createMessage();
- $message->setTo([$email => $this->userSession->getUser()->getDisplayName()]);
- $message->setFrom([$this->defaultMailAddress]);
- $message->setSubject($this->l10n->t('test email settings'));
- $message->setPlainBody('If you received this email, the settings seem to be correct.');
+ $message->setTo([$email => $displayName]);
+ $message->setSubject($this->l10n->t('Email setting test'));
+ $message->setHtmlBody($template->renderHTML());
+ $message->setPlainBody($template->renderText());
$errors = $this->mailer->send($message);
if (!empty($errors)) {
throw new \RuntimeException($this->l10n->t('Mail could not be sent. Check your mail server log'));
}
+ return new DataResponse();
} catch (\Exception $e) {
- return [
- 'data' => [
- 'message' => (string) $this->l10n->t('A problem occurred while sending the email. Please revise your settings. (Error: %s)', [$e->getMessage()]),
- ],
- 'status' => 'error',
- ];
+ return new DataResponse($this->l10n->t('A problem occurred while sending the email. Please revise your settings. (Error: %s)', [$e->getMessage()]), Http::STATUS_BAD_REQUEST);
}
-
- return array('data' =>
- array('message' =>
- (string) $this->l10n->t('Email sent')
- ),
- 'status' => 'success'
- );
}
- return array('data' =>
- array('message' =>
- (string) $this->l10n->t('You need to set your user email before being able to send test emails.'),
- ),
- 'status' => 'error'
- );
+ return new DataResponse($this->l10n->t('You need to set your user email before being able to send test emails.'), Http::STATUS_BAD_REQUEST);
}
}