diff options
author | Lukas Reschke <lukas@owncloud.com> | 2015-02-12 16:03:51 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2015-03-16 12:47:05 +0100 |
commit | 283476a2f7c200912352eb4db097f540e3993e75 (patch) | |
tree | 7f98a98e15f8ec4d4f2f39e5863186cc4c1cd47b /core | |
parent | 13486a5ada62e4355473ca01e07371c162951e84 (diff) | |
download | nextcloud-server-283476a2f7c200912352eb4db097f540e3993e75.tar.gz nextcloud-server-283476a2f7c200912352eb4db097f540e3993e75.zip |
Use new IMailer and add unit-tests for lostcontroller
Diffstat (limited to 'core')
-rw-r--r-- | core/application.php | 6 | ||||
-rw-r--r-- | core/lostpassword/controller/lostcontroller.php | 24 |
2 files changed, 19 insertions, 11 deletions
diff --git a/core/application.php b/core/application.php index 568fc34db7d..34f817aa391 100644 --- a/core/application.php +++ b/core/application.php @@ -46,7 +46,8 @@ class Application extends App { $c->query('Config'), $c->query('SecureRandom'), $c->query('DefaultEmailAddress'), - $c->query('IsEncryptionEnabled') + $c->query('IsEncryptionEnabled'), + $c->query('Mailer') ); }); $container->registerService('UserController', function(SimpleContainer $c) { @@ -104,6 +105,9 @@ class Application extends App { $container->registerService('Defaults', function() { return new \OC_Defaults; }); + $container->registerService('Mailer', function(SimpleContainer $c) { + return $c->query('ServerContainer')->getMailer(); + }); $container->registerService('DefaultEmailAddress', function() { return Util::getDefaultEmailAddress('lostpassword-noreply'); }); diff --git a/core/lostpassword/controller/lostcontroller.php b/core/lostpassword/controller/lostcontroller.php index d1a4528d449..08f5246503f 100644 --- a/core/lostpassword/controller/lostcontroller.php +++ b/core/lostpassword/controller/lostcontroller.php @@ -15,6 +15,7 @@ use \OCP\IRequest; use \OCP\IL10N; use \OCP\IConfig; use OCP\IUserManager; +use OCP\Mail\IMailer; use OCP\Security\ISecureRandom; use \OC_Defaults; use OCP\Security\StringUtils; @@ -32,6 +33,7 @@ class LostController extends Controller { protected $urlGenerator; /** @var IUserManager */ protected $userManager; + // FIXME: Inject a non-static factory of OC_Defaults for better unit-testing /** @var OC_Defaults */ protected $defaults; /** @var IL10N */ @@ -44,6 +46,8 @@ class LostController extends Controller { protected $config; /** @var ISecureRandom */ protected $secureRandom; + /** @var IMailer */ + protected $mailer; /** * @param string $appName @@ -56,6 +60,7 @@ class LostController extends Controller { * @param ISecureRandom $secureRandom * @param string $from * @param string $isDataEncrypted + * @param IMailer $mailer */ public function __construct($appName, IRequest $request, @@ -66,7 +71,8 @@ class LostController extends Controller { IConfig $config, ISecureRandom $secureRandom, $from, - $isDataEncrypted) { + $isDataEncrypted, + IMailer $mailer) { parent::__construct($appName, $request); $this->urlGenerator = $urlGenerator; $this->userManager = $userManager; @@ -76,6 +82,7 @@ class LostController extends Controller { $this->from = $from; $this->isDataEncrypted = $isDataEncrypted; $this->config = $config; + $this->mailer = $mailer; } /** @@ -200,15 +207,12 @@ class LostController extends Controller { $msg = $tmpl->fetchPage(); try { - // FIXME: should be added to the container and injected in here - \OCP\Util::sendMail( - $email, - $user, - $this->l10n->t('%s password reset', array($this->defaults->getName())), - $msg, - $this->from, - $this->defaults->getName() - ); + $message = $this->mailer->createMessage(); + $message->setTo([$email => $user]); + $message->setSubject($this->l10n->t('%s password reset', [$this->defaults->getName()])); + $message->setPlainBody($msg); + $message->setFrom([$this->from => $this->defaults->getName()]); + $this->mailer->send($message); } catch (\Exception $e) { throw new \Exception($this->l10n->t( 'Couldn\'t send reset email. Please contact your administrator.' |