Ejemplo n.º 1
0
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  * @PublicPage
  */
 public function validateEmail()
 {
     $email = $this->request->getParam('email');
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         return new TemplateResponse('', 'error', array(array('error' => $this->l10n->t('Email address you entered is not valid'))), 'error');
         return new TemplateResponse('', 'error', array('errors' => array(array('error' => $this->l10n->t('Email address you entered is not valid'), 'hint' => ''))), 'error');
     }
     if ($this->pendingreg->find($email)) {
         return new TemplateResponse('', 'error', array('errors' => array(array('error' => $this->l10n->t('There is already a pending registration with this email'), 'hint' => ''))), 'error');
     }
     if ($this->config->getUsersForUserValue('settings', 'email', $email)) {
         return new TemplateResponse('', 'error', array('errors' => array(array('error' => $this->l10n->t('There is an existing user with this email'), 'hint' => ''))), 'error');
     }
     // FEATURE: allow only from specific email domain
     $token = $this->pendingreg->save($email);
     //TODO: check for error
     $link = $this->urlgenerator->linkToRoute('registration.register.verifyToken', array('token' => $token));
     $link = $this->urlgenerator->getAbsoluteURL($link);
     $from = Util::getDefaultEmailAddress('register');
     $res = new TemplateResponse('registration', 'email', array('link' => $link), 'blank');
     $msg = $res->render();
     try {
         $this->mail->sendMail($email, 'ownCloud User', $this->l10n->t('Verify your ownCloud registration request'), $msg, $from, 'ownCloud');
     } catch (\Exception $e) {
         \OC_Template::printErrorPage('A problem occurs during sending the e-mail please contact your administrator.');
         return;
     }
     return new TemplateResponse('registration', 'message', array('msg' => $this->l10n->t('Verification email successfully sent.')), 'guest');
 }
 public function testSlideshow()
 {
     $template = new TemplateResponse($this->appName, 'slideshow', [], 'blank');
     $response = $this->controller->slideshow();
     $this->assertEquals('slideshow', $response->getTemplateName());
     $this->assertTrue($response instanceof TemplateResponse);
     $this->assertEquals($template->render(), $response->render());
 }
Ejemplo n.º 3
0
 * ownCloud - agreedisclaimer
 *
 * This file is licensed under the MIT License. See the LICENSE file.
 *
 * @author Josef Meile <*****@*****.**>
 * @copyright Josef Meile 2015
 */
namespace OCA\AgreeDisclaimer;

use OCP\AppFramework\Http\TemplateResponse;
use OCA\AgreeDisclaimer\AppInfo\Application;
/**
 * Renders the app settings on the admin page
 *
 * @return string   The template rendered as html
 */
$app = new Application();
$appName = $app->getAppName();
$container = $app->getContainer();
$config = $app->getConfig();
$utils = $app->getUtils();
$defaultLang = $config->getDefaultLang();
$localeInfo = $utils->getAvailableLanguages($defaultLang);
//Fix it: I'm not sure if there is a better way of getting l10n from this
//script, ie: something like in the templates: $l->...
$l10n = $app->getContainer()->getServer()->getL10N($appName);
$userLang = $l10n->getLanguageCode();
$data = ['appName' => $appName, 'filePreffix' => $container->query('filePreffix'), 'datepickerAppFormat' => $config->getDatepickerDateFormat(), 'cookieData' => $config->getCookieData(true), 'txtFileData' => $config->getTxtFileData(false, true), 'pdfFileData' => $config->getPdfFileData(false, true), 'disclaimerType' => $config->getDisclaimerType(), 'disclaimerTypes' => $config->getDisclaimerTypes(true), 'disclaimerLayout' => $config->getDisclaimerLayout(), 'disclaimerLayouts' => $config->getDisclaimerLayouts(), 'userLang' => $userLang, 'currentLang' => $localeInfo['activelanguage'], 'commonLanguages' => $localeInfo['commonlanguages'], 'availableLanguages' => $localeInfo['languages']];
$templateResponse = new TemplateResponse($appName, 'admin', $data, 'blank');
return $templateResponse->render();
Ejemplo n.º 4
0
 /**
  * @NoAdminRequired
  *
  * @param string $username
  * @param string $password
  * @param array $groups
  * @param string $email
  * @return DataResponse
  */
 public function create($username, $password, array $groups = array(), $email = '')
 {
     if ($email !== '' && !$this->mailer->validateMailAddress($email)) {
         return new DataResponse(array('message' => (string) $this->l10n->t('Invalid mail address')), Http::STATUS_UNPROCESSABLE_ENTITY);
     }
     $currentUser = $this->userSession->getUser();
     if (!$this->isAdmin) {
         if (!empty($groups)) {
             foreach ($groups as $key => $group) {
                 $groupObject = $this->groupManager->get($group);
                 if ($groupObject === null) {
                     unset($groups[$key]);
                     continue;
                 }
                 if (!$this->groupManager->getSubAdmin()->isSubAdminofGroup($currentUser, $groupObject)) {
                     unset($groups[$key]);
                 }
             }
         }
         if (empty($groups)) {
             $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($currentUser);
             // New class returns IGroup[] so convert back
             $gids = [];
             foreach ($groups as $group) {
                 $gids[] = $group->getGID();
             }
             $groups = $gids;
         }
     }
     if ($this->userManager->userExists($username)) {
         return new DataResponse(array('message' => (string) $this->l10n->t('A user with that name already exists.')), Http::STATUS_CONFLICT);
     }
     try {
         $user = $this->userManager->createUser($username, $password);
     } catch (\Exception $exception) {
         return new DataResponse(array('message' => (string) $this->l10n->t('Unable to create user.')), Http::STATUS_FORBIDDEN);
     }
     if ($user instanceof User) {
         if ($groups !== null) {
             foreach ($groups as $groupName) {
                 $group = $this->groupManager->get($groupName);
                 if (empty($group)) {
                     $group = $this->groupManager->createGroup($groupName);
                 }
                 $group->addUser($user);
             }
         }
         /**
          * Send new user mail only if a mail is set
          */
         if ($email !== '') {
             $this->config->setUserValue($username, 'settings', 'email', $email);
             // data for the mail template
             $mailData = array('username' => $username, 'url' => $this->urlGenerator->getAbsoluteURL('/'));
             $mail = new TemplateResponse('settings', 'email.new_user', $mailData, 'blank');
             $mailContent = $mail->render();
             $mail = new TemplateResponse('settings', 'email.new_user_plain_text', $mailData, 'blank');
             $plainTextMailContent = $mail->render();
             $subject = $this->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);
             } catch (\Exception $e) {
                 $this->log->error("Can't send new user mail to {$email}: " . $e->getMessage(), array('app' => 'settings'));
             }
         }
         // fetch users groups
         $userGroups = $this->groupManager->getUserGroupIds($user);
         return new DataResponse($this->formatUserForIndex($user, $userGroups), Http::STATUS_CREATED);
     }
     return new DataResponse(array('message' => (string) $this->l10n->t('Unable to create user.')), Http::STATUS_FORBIDDEN);
 }
Ejemplo n.º 5
0
 /**
  * @NoAdminRequired
  *
  * @param string $username
  * @param string $password
  * @param array $groups
  * @param string $email
  * @return DataResponse
  *
  * TODO: Tidy up and write unit tests - code is mainly static method calls
  */
 public function create($username, $password, array $groups = array(), $email = '')
 {
     if ($email !== '' && !$this->mail->validateAddress($email)) {
         return new DataResponse(array('message' => (string) $this->l10n->t('Invalid mail address')), Http::STATUS_UNPROCESSABLE_ENTITY);
     }
     // TODO FIXME get rid of the static calls to OC_Subadmin
     if (!$this->isAdmin) {
         if (!empty($groups)) {
             foreach ($groups as $key => $group) {
                 if (!\OC_SubAdmin::isGroupAccessible($this->userSession->getUser()->getUID(), $group)) {
                     unset($groups[$key]);
                 }
             }
         }
         if (empty($groups)) {
             $groups = \OC_SubAdmin::getSubAdminsGroups($this->userSession->getUser()->getUID());
         }
     }
     try {
         $user = $this->userManager->createUser($username, $password);
     } catch (\Exception $exception) {
         return new DataResponse(array('message' => (string) $this->l10n->t('Unable to create user.')), Http::STATUS_FORBIDDEN);
     }
     if ($user instanceof User) {
         if ($groups !== null) {
             foreach ($groups as $groupName) {
                 $group = $this->groupManager->get($groupName);
                 if (empty($group)) {
                     $group = $this->groupManager->createGroup($groupName);
                 }
                 $group->addUser($user);
             }
         }
         /**
          * Send new user mail only if a mail is set
          */
         if ($email !== '') {
             $this->config->setUserValue($username, 'settings', 'email', $email);
             // data for the mail template
             $mailData = array('username' => $username, 'url' => $this->urlGenerator->getAbsoluteURL('/'));
             $mail = new TemplateResponse('settings', 'email.new_user', $mailData, 'blank');
             $mailContent = $mail->render();
             $mail = new TemplateResponse('settings', 'email.new_user_plain_text', $mailData, 'blank');
             $plainTextMailContent = $mail->render();
             $subject = $this->l10n->t('Your %s account was created', [$this->defaults->getName()]);
             try {
                 $this->mail->send($email, $username, $subject, $mailContent, $this->fromMailAddress, $this->defaults->getName(), 1, $plainTextMailContent);
             } catch (\Exception $e) {
                 $this->log->error("Can't send new user mail to {$email}: " . $e->getMessage(), array('app' => 'settings'));
             }
         }
         // fetch users groups
         $userGroups = $this->groupManager->getUserGroupIds($user);
         return new DataResponse($this->formatUserForIndex($user, $userGroups), Http::STATUS_CREATED);
     }
     return new DataResponse(array('message' => (string) $this->l10n->t('Unable to create user.')), Http::STATUS_FORBIDDEN);
 }
Ejemplo n.º 6
0
 /**
  * Render views and transmit data to it
  * @param $appName
  * @param $view
  * @param array $data
  * @return string
  */
 public static function renderPartial($appName, $view, array $data = [])
 {
     $response = new TemplateResponse($appName, $view, $data, '');
     return $response->render();
 }
Ejemplo n.º 7
0
 /**
  * @NoAdminRequired
  */
 public function editCalendar()
 {
     $calendarid = (int) $this->params('id');
     $pName = (string) $this->params('name');
     $pActive = (int) $this->params('active');
     $pColor = (string) $this->params('color');
     if (trim($pName) === '') {
         $params = ['status' => 'error', 'message' => 'empty'];
         $response = new JSONResponse($params);
         return $response;
     }
     $calendars = CalendarCalendar::allCalendars($this->userId);
     foreach ($calendars as $cal) {
         if ($cal['userid'] !== $this->userId) {
             continue;
         }
         if ($cal['displayname'] === $pName && (int) $cal['id'] !== $calendarid) {
             $params = ['status' => 'error', 'message' => 'namenotavailable'];
             $response = new JSONResponse($params);
             return $response;
         }
     }
     try {
         CalendarCalendar::editCalendar($calendarid, strip_tags($pName), null, null, null, $pColor, null);
         CalendarCalendar::setCalendarActive($calendarid, $pActive);
     } catch (Exception $e) {
         $params = ['status' => 'error', 'message' => $e->getMessage()];
         $response = new JSONResponse($params);
         return $response;
     }
     $calendar = CalendarCalendar::find($calendarid);
     $isShareApiActive = \OC::$server->getAppConfig()->getValue('core', 'shareapi_enabled', 'yes');
     $shared = false;
     if ($calendar['userid'] !== $this->userId) {
         $sharedCalendar = \OCP\Share::getItemSharedWithBySource(CalendarApp::SHARECALENDAR, CalendarApp::SHARECALENDARPREFIX . $calendarid);
         if ($sharedCalendar && $sharedCalendar['permissions'] & \OCP\PERMISSION_UPDATE) {
             $shared = true;
         }
     }
     $paramsList = ['calendar' => $calendar, 'shared' => $shared, 'appname' => $this->appName, 'isShareApi' => $isShareApiActive];
     $calendarRow = new TemplateResponse($this->appName, 'part.choosecalendar.rowfields', $paramsList, '');
     $params = ['status' => 'success', 'eventSource' => CalendarCalendar::getEventSourceInfo($calendar), 'calid' => $calendarid, 'countEvents' => false, 'page' => $calendarRow->render()];
     $response = new JSONResponse($params);
     return $response;
 }
Ejemplo n.º 8
0
 /**
  * Send an e-mail with content from templates
  *
  * @param \OCP\AppFramework\Http\TemplateResponse $htmlTemplate HTML
  * mail content
  * @param \OCP\AppFramework\Http\TemplateResponse $plainTemplate mail
  * content in plaintext
  */
 private function sendMail($uid, $emailAddress, $subject, $htmlTemplate, $plainTemplate)
 {
     try {
         $message = $this->mailer->createMessage();
         $message->setTo([$emailAddress => $uid]);
         $message->setSubject($subject);
         $message->setHtmlBody($htmlTemplate->render());
         $message->setPlainBody($plainTemplate->render());
         $message->setFrom([$this->fromMailAddress => $this->defaults->getName()]);
         $this->mailer->send($message);
     } catch (\Exception $e) {
         $this->logger->error('Can\'t send new user mail to' . $emailAddress . ': ' . $e->getMessage(), $this->logCtx);
     }
 }
 /**
  * Sends new user notification email to admin
  * @param array $to
  * @param string $username the new user
  * @return null
  * @throws \Exception
  */
 private function sendNewUserNotifEmail(array $to, string $username)
 {
     $template_var = ['user' => $username, 'sitename' => $this->defaults->getName()];
     $html_template = new TemplateResponse('registration', 'email.newuser_html', $template_var, 'blank');
     $html_part = $html_template->render();
     $plaintext_template = new TemplateResponse('registration', 'email.newuser_plaintext', $template_var, 'blank');
     $plaintext_part = $plaintext_template->render();
     $subject = $this->l10n->t('A new user "%s" had created an account on %s', [$username, $this->defaults->getName()]);
     $from = Util::getDefaultEmailAddress('register');
     $message = $this->mailer->createMessage();
     $message->setFrom([$from => $this->defaults->getName()]);
     $message->setTo($to);
     $message->setSubject($subject);
     $message->setPlainBody($plaintext_part);
     $message->setHtmlBody($html_part);
     $failed_recipients = $this->mailer->send($message);
     if (!empty($failed_recipients)) {
         throw new \Exception('Failed recipients: ' . print_r($failed_recipients, true));
     }
 }
Ejemplo n.º 10
0
 /**
  * Renders the disclaimer on the user's menu
  */
 public function renderDisclaimerMenu()
 {
     $container = $this->getContainer();
     $session = $container->query('OCP\\IUserSession');
     if ($session->isLoggedIn()) {
         $data = ['appName' => $this->appName];
         $templateResponse = new TemplateResponse($this->appName, 'user', $data, 'blank');
         return $templateResponse->render();
     }
     return null;
 }
Ejemplo n.º 11
0
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function index()
 {
     if (\OC::$server->getAppManager()->isEnabledForUser('contactsplus')) {
         $appinfo = \OCP\App::getAppVersion('contactsplus');
         if (version_compare($appinfo, '1.0.6', '>=')) {
             $calId = $this->calendarController->checkBirthdayCalendarByUri('bdaycpltocal_' . $this->userId);
         }
     }
     $calendars = CalendarCalendar::allCalendars($this->userId, false, false, false);
     if (count($calendars) == 0) {
         CalendarCalendar::addDefaultCalendars($this->userId);
         $calendars = CalendarCalendar::allCalendars($this->userId, true);
     }
     if ($this->configInfo->getUserValue($this->userId, $this->appName, 'currentview', 'month') == "onedayview") {
         $this->configInfo->setUserValue($this->userId, $this->appName, 'currentview', "agendaDay");
     }
     if ($this->configInfo->getUserValue($this->userId, $this->appName, 'currentview', 'month') == "oneweekview") {
         $this->configInfo->setUserValue($this->userId, $this->appName, 'currentview', "agendaWeek");
     }
     if ($this->configInfo->getUserValue($this->userId, $this->appName, 'currentview', 'month') == "onemonthview") {
         $this->configInfo->setUserValue($this->userId, $this->appName, 'currentview', "month");
     }
     if ($this->configInfo->getUserValue($this->userId, $this->appName, 'currentview', 'month') == "listview") {
         $this->configInfo->setUserValue($this->userId, $this->appName, 'currentview', "list");
     }
     if ($this->configInfo->getUserValue($this->userId, $this->appName, 'currentview', 'month') == "fourweeksview") {
         $this->configInfo->setUserValue($this->userId, $this->appName, 'currentview', "fourweeks");
     }
     \OCP\Util::addStyle($this->appName, '3rdparty/colorPicker');
     \OCP\Util::addscript($this->appName, '3rdparty/jquery.colorPicker');
     \OCP\Util::addScript($this->appName, '3rdparty/fullcalendar');
     \OCP\Util::addStyle($this->appName, '3rdparty/fullcalendar');
     \OCP\Util::addStyle($this->appName, '3rdparty/jquery.timepicker');
     \OCP\Util::addStyle($this->appName, '3rdparty/fontello/css/animation');
     \OCP\Util::addStyle($this->appName, '3rdparty/fontello/css/fontello');
     \OCP\Util::addScript($this->appName, 'jquery.scrollTo.min');
     //\OCP\Util::addScript($this->appName,'timepicker');
     \OCP\Util::addScript($this->appName, '3rdparty/datepair');
     \OCP\Util::addScript($this->appName, '3rdparty/jquery.datepair');
     \OCP\Util::addScript($this->appName, '3rdparty/jquery.timepicker');
     \OCP\Util::addScript($this->appName, "3rdparty/jquery.webui-popover");
     \OCP\Util::addScript($this->appName, "3rdparty/chosen.jquery.min");
     \OCP\Util::addStyle($this->appName, "3rdparty/chosen");
     \OCP\Util::addScript($this->appName, '3rdparty/tag-it');
     \OCP\Util::addStyle($this->appName, '3rdparty/jquery.tagit');
     \OCP\Util::addStyle($this->appName, '3rdparty/jquery.webui-popover');
     if ($this->configInfo->getUserValue($this->userId, $this->appName, 'timezone') == null || $this->configInfo->getUserValue($this->userId, $this->appName, 'timezonedetection') == 'true') {
         \OCP\Util::addScript($this->appName, '3rdparty/jstz-1.0.4.min');
         \OCP\Util::addScript($this->appName, 'geo');
     }
     \OCP\Util::addScript($this->appName, '3rdparty/printThis');
     \OCP\Util::addScript($this->appName, 'app');
     \OCP\Util::addScript($this->appName, 'loaderimport');
     \OCP\Util::addStyle($this->appName, 'style');
     \OCP\Util::addStyle($this->appName, "mobile");
     \OCP\Util::addScript($this->appName, 'jquery.multi-autocomplete');
     \OCP\Util::addScript('core', 'tags');
     \OCP\Util::addScript($this->appName, 'on-event');
     $leftNavAktiv = $this->configInfo->getUserValue($this->userId, $this->appName, 'calendarnav');
     $rightNavAktiv = $this->configInfo->getUserValue($this->userId, $this->appName, 'tasknav');
     $pCalendar = $calendars;
     $pHiddenCal = 'class="isHiddenCal"';
     $pButtonCalAktive = '';
     if ($leftNavAktiv === 'true') {
         $pHiddenCal = '';
         $pButtonCalAktive = 'button-info';
     }
     $pButtonTaskAktive = '';
     $pTaskOutput = '';
     $pRightnavAktiv = $rightNavAktiv;
     $pIsHidden = 'class="isHiddenTask"';
     if ($rightNavAktiv === 'true' && \OC::$server->getAppManager()->isEnabledForUser('tasksplus')) {
         $allowedCals = [];
         foreach ($calendars as $calInfo) {
             $isAktiv = (int) $calInfo['active'];
             if ($this->configInfo->getUserValue($this->userId, $this->appName, 'calendar_' . $calInfo['id']) !== '') {
                 $isAktiv = (int) $this->configInfo->getUserValue($this->userId, $this->appName, 'calendar_' . $calInfo['id']);
             }
             if ($isAktiv === 1) {
                 $allowedCals[] = $calInfo;
             }
         }
         $cDataTimeLine = new \OCA\TasksPlus\Timeline();
         $cDataTimeLine->setCalendars($allowedCals);
         $taskOutPutbyTime = $cDataTimeLine->generateAddonCalendarTodo();
         $paramsList = ['taskOutPutbyTime' => $taskOutPutbyTime];
         $list = new TemplateResponse('tasksplus', 'calendars.tasks.list', $paramsList, '');
         $pButtonTaskAktive = 'button-info';
         $pTaskOutput = $list->render();
         $pIsHidden = '';
     }
     $params = ['calendars' => $pCalendar, 'leftnavAktiv' => $leftNavAktiv, 'isHiddenCal' => $pHiddenCal, 'buttonCalAktive' => $pButtonCalAktive, 'isHidden' => $pIsHidden, 'buttonTaskAktive' => $pButtonTaskAktive, 'taskOutput' => $pTaskOutput, 'rightnavAktiv' => $pRightnavAktiv, 'mailNotificationEnabled' => \OC::$server->getAppConfig()->getValue('core', 'shareapi_allow_mail_notification', 'yes'), 'allowShareWithLink' => \OC::$server->getAppConfig()->getValue('core', 'shareapi_allow_links', 'yes'), 'mailPublicNotificationEnabled' => \OC::$server->getAppConfig()->getValue('core', 'shareapi_allow_public_notification', 'no')];
     $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
     $csp->addAllowedImageDomain('*');
     $response = new TemplateResponse($this->appName, 'calendar', $params);
     $response->setContentSecurityPolicy($csp);
     return $response;
 }
Ejemplo n.º 12
0
 /**
  * test if a valid mail result in a successful mail send
  */
 public function testCreateSuccessfulWithValidEmailAdmin()
 {
     $this->container['IsAdmin'] = true;
     $message = $this->getMockBuilder('\\OC\\Mail\\Message')->disableOriginalConstructor()->getMock();
     $message->expects($this->at(0))->method('setTo')->with(['*****@*****.**' => 'foo']);
     $message->expects($this->at(1))->method('setSubject')->with('Your  account was created');
     $htmlBody = new Http\TemplateResponse('settings', 'email.new_user', ['username' => 'foo', 'url' => ''], 'blank');
     $message->expects($this->at(2))->method('setHtmlBody')->with($htmlBody->render());
     $plainBody = new Http\TemplateResponse('settings', 'email.new_user_plain_text', ['username' => 'foo', 'url' => ''], 'blank');
     $message->expects($this->at(3))->method('setPlainBody')->with($plainBody->render());
     $message->expects($this->at(4))->method('setFrom')->with(['*****@*****.**' => null]);
     $this->container['Mailer']->expects($this->at(0))->method('validateMailAddress')->with('*****@*****.**')->will($this->returnValue(true));
     $this->container['Mailer']->expects($this->at(1))->method('createMessage')->will($this->returnValue($message));
     $this->container['Mailer']->expects($this->at(2))->method('send')->with($message);
     $user = $this->getMockBuilder('\\OC\\User\\User')->disableOriginalConstructor()->getMock();
     $user->method('getHome')->will($this->returnValue('/home/user'));
     $user->method('getHome')->will($this->returnValue('/home/user'));
     $user->method('getUID')->will($this->returnValue('foo'));
     $user->expects($this->once())->method('getBackendClassName')->will($this->returnValue('bar'));
     $this->container['UserManager']->expects($this->once())->method('createUser')->will($this->onConsecutiveCalls($user));
     $subadmin = $this->getMockBuilder('\\OC\\SubAdmin')->disableOriginalConstructor()->getMock();
     $subadmin->expects($this->once())->method('getSubAdminsGroups')->with($user)->will($this->returnValue([]));
     $this->container['GroupManager']->expects($this->any())->method('getSubAdmin')->will($this->returnValue($subadmin));
     $response = $this->container['UsersController']->create('foo', 'password', [], '*****@*****.**');
     $this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
 }
Ejemplo n.º 13
0
 /**
  * Sends validation email
  * @param string $token
  * @param string $to
  * @return null
  * @throws \Exception
  */
 private function sendValidationEmail(string $token, string $to)
 {
     $link = $this->urlgenerator->linkToRoute('registration.register.verifyToken', array('token' => $token));
     $link = $this->urlgenerator->getAbsoluteURL($link);
     $html_template = new TemplateResponse('registration', 'email_html', array('link' => $link), 'blank');
     $html_part = $html_template->render();
     $plaintext_template = new TemplateResponse('registration', 'email_plaintext', array('link' => $link), 'blank');
     $plaintext_part = $plaintext_template->render();
     $subject = $this->l10n->t('Verify your ownCloud registration request');
     $from = Util::getDefaultEmailAddress('register');
     $message = $this->mailer->createMessage();
     $message->setFrom([$from]);
     $message->setTo([$to]);
     $message->setSubject($subject);
     $message->setPlainBody($plaintext_part);
     $message->setHtmlBody($html_part);
     $failed_recipients = $this->mailer->send($message);
     if (!empty($failed_recipients)) {
         throw new \Exception('Failed recipients: ' . print_r($failed_recipients, true));
     }
 }