summaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-04-07 14:52:28 -0500
committerGitHub <noreply@github.com>2017-04-07 14:52:28 -0500
commit8838ed4c2ea50e9205dd7b106bf6aeda9e0a1171 (patch)
treefa652016000acb8df5838a7d3e0049e7079ecb9f /apps/provisioning_api/lib
parent4c60360bf733fab8882939f2cd9dca57b6fe405e (diff)
parent8daf3d4a70bc97b6680956f6b13143e184a83c96 (diff)
downloadnextcloud-server-8838ed4c2ea50e9205dd7b106bf6aeda9e0a1171.tar.gz
nextcloud-server-8838ed4c2ea50e9205dd7b106bf6aeda9e0a1171.zip
Merge pull request #4244 from nextcloud/welcome-email
New layout for welcome email
Diffstat (limited to 'apps/provisioning_api/lib')
-rw-r--r--apps/provisioning_api/lib/AppInfo/Application.php16
-rw-r--r--apps/provisioning_api/lib/Controller/UsersController.php34
2 files changed, 26 insertions, 24 deletions
diff --git a/apps/provisioning_api/lib/AppInfo/Application.php b/apps/provisioning_api/lib/AppInfo/Application.php
index 2d6a82e2ff9..fd03fd41e16 100644
--- a/apps/provisioning_api/lib/AppInfo/Application.php
+++ b/apps/provisioning_api/lib/AppInfo/Application.php
@@ -3,8 +3,11 @@
namespace OCA\Provisioning_API\AppInfo;
use OC\AppFramework\Utility\SimpleContainer;
+use OC\AppFramework\Utility\TimeFactory;
+use OC\Settings\Mailer\NewUserMailHelper;
use OCA\Provisioning_API\Middleware\ProvisioningApiMiddleware;
use OCP\AppFramework\App;
+use OCP\Util;
class Application extends App {
public function __construct(array $urlParams = array()) {
@@ -13,6 +16,19 @@ class Application extends App {
$container = $this->getContainer();
$server = $container->getServer();
+ $container->registerService(NewUserMailHelper::class, function(SimpleContainer $c) use ($server) {
+ return new NewUserMailHelper(
+ $server->getThemingDefaults(),
+ $server->getURLGenerator(),
+ $server->getL10N('settings'),
+ $server->getMailer(),
+ $server->getSecureRandom(),
+ new TimeFactory(),
+ $server->getConfig(),
+ $server->getCrypto(),
+ Util::getDefaultEmailAddress('no-reply')
+ );
+ });
$container->registerService('ProvisioningApiMiddleware', function(SimpleContainer $c) use ($server) {
$user = $server->getUserManager()->get($c['UserId']);
$isAdmin = $user !== null ? $server->getGroupManager()->isAdmin($user->getUID()) : false;
diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php
index cb4e4b32917..9684c7f5656 100644
--- a/apps/provisioning_api/lib/Controller/UsersController.php
+++ b/apps/provisioning_api/lib/Controller/UsersController.php
@@ -30,6 +30,7 @@
namespace OCA\Provisioning_API\Controller;
use OC\Accounts\AccountManager;
+use OC\Settings\Mailer\NewUserMailHelper;
use \OC_Helper;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\TemplateResponse;
@@ -72,6 +73,8 @@ class UsersController extends OCSController {
private $defaults;
/** @var IFactory */
private $l10nFactory;
+ /** @var NewUserMailHelper */
+ private $newUserMailHelper;
/**
* @param string $appName
@@ -87,6 +90,7 @@ class UsersController extends OCSController {
* @param IMailer $mailer
* @param \OC_Defaults $defaults
* @param IFactory $l10nFactory
+ * @param NewUserMailHelper $newUserMailHelper
*/
public function __construct($appName,
IRequest $request,
@@ -100,7 +104,8 @@ class UsersController extends OCSController {
IURLGenerator $urlGenerator,
IMailer $mailer,
\OC_Defaults $defaults,
- IFactory $l10nFactory) {
+ IFactory $l10nFactory,
+ NewUserMailHelper $newUserMailHelper) {
parent::__construct($appName, $request);
$this->userManager = $userManager;
@@ -114,6 +119,7 @@ class UsersController extends OCSController {
$this->mailer = $mailer;
$this->defaults = $defaults;
$this->l10nFactory = $l10nFactory;
+ $this->newUserMailHelper = $newUserMailHelper;
}
/**
@@ -807,30 +813,10 @@ class UsersController extends OCSController {
$l10n = $this->l10nFactory->get('settings', $lang);
- // data for the mail template
- $mailData = [
- 'username' => $username,
- 'url' => $this->urlGenerator->getAbsoluteURL('/')
- ];
-
- // FIXME: set users language in email
- $mail = new TemplateResponse('settings', 'email.new_user', $mailData, 'blank');
- $mailContent = $mail->render();
-
- // FIXME: set users language in email
- $mail = new TemplateResponse('settings', 'email.new_user_plain_text', $mailData, 'blank');
- $plainTextMailContent = $mail->render();
-
- $subject = $l10n->t('Your %s account was created', [$this->defaults->getName()]);
-
try {
- $message = $this->mailer->createMessage();
- $message->setTo([$email => $username]);
- $message->setSubject($subject);
- $message->setHtmlBody($mailContent);
- $message->setPlainBody($plainTextMailContent);
- $message->setFrom([$this->fromMailAddress => $this->defaults->getName()]);
- $this->mailer->send($message);
+ $this->newUserMailHelper->setL10N($l10n);
+ $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false);
+ $this->newUserMailHelper->sendMail($targetUser, $emailTemplate);
} catch(\Exception $e) {
$this->logger->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings'));
throw new OCSException('Sending email failed', 102);