translator->getLocale(); $this->translator->setLocale($locale); } $templateName .= '.latte'; $dirname = dirname(new ReflectionClass($this)->getFileName()) . '/templates/'; $templateFile = $dirname . $templateName; if (!file_exists($templateFile)) { $templateFile = __DIR__ . '/templates/' . $templateName; } $layoutName = '@layout.latte'; $layoutFile = dirname(new ReflectionClass($this)->getFileName()) . '/templates/' . $layoutName; if (!file_exists($layoutFile)) { $layoutFile = __DIR__ . '/templates/' . $layoutName; } /** @var Template $template */ $template = $this->templateFactory->createTemplate(); $template->addFilter('translate', [$this->translator, 'translate']) ->setFile($templateFile); $template->projectName = $this->administration->getProjectName(); $template->fromName = $this->fromName; $template->logoFileName = $this->administration->getLogoBitmapPublicPath(); $template->backgroundColor = $this->administration->getEmailBackgroundColor(); $template->subject = $this->translator->translate($subject, $translateVariables); $template->layoutFile = $layoutFile; foreach ($data as $key => $value) { $template->$key = $value; } foreach (['supportEmail', 'title', 'web'] as $privateParam) { $template->$privateParam = $this->$privateParam; } $message = static::createMessage() ->setSubject($this->translator->translate($subject, $translateVariables)) ->setHtmlBody( new CssToInlineStyles\CssToInlineStyles()->convert((string) $template), $this->wwwDir ); if (isset($originalLocale)) { $this->translator->setLocale($originalLocale); } return $message; } /** * @throws Exception */ public function send(Message $mail): void { if (! $mail->getFrom() && $this->from) { $mail->setFrom($this->from, $this->fromName) ->addReplyTo($this->supportEmail, $this->fromName); } if (! empty($this->singleRecipient)) { $this->applySingleRecipient($mail, $this->singleRecipient); } $this->mailer->send($mail); } /** * @throws InvalidArgument * @throws DateMalformedStringException * @throws Exception */ public function sendAccountCreationEmail(Identity $identity, bool $checkLimit = true): void { $this->em->beginTransaction(); $token = $this->onetimeTokenService->saveToken(OnetimeTokenTypeEnum::LOGIN, new DateTimeImmutable('+' . OnetimeToken::PASSWORD_CREATION_VALID_FOR . ' hours'), $identity, checkLimit: $checkLimit); $message = $this->createTemplateMessage( 'accountCreation', 'Vytvoření účtu', [ 'link' => $this->link(':Portal:Sign:newPassword', ['email' => $identity->getEmail(), 'token' => $token]) ] ); $message->addTo($identity->getEmail()); $this->send($message); $this->em->commit(); } /** * @throws DateMalformedStringException * @throws InvalidArgument * @throws Exception */ public function sendPasswordRecoveryMail(Identity $identity, int $tokenLifetime, bool $checkLimit = true): void { $this->em->beginTransaction(); $token = $this->onetimeTokenService->saveToken(OnetimeTokenTypeEnum::LOGIN, new DateTimeImmutable('+ ' . $tokenLifetime . ' hour'), $identity, checkLimit: $checkLimit); $message = $this->createTemplateMessage( 'passwordRecovery', 'Nové heslo', [ 'link' => $this->link(':Portal:Sign:newPassword', ['email' => $identity->getEmail(), 'token' => $token]), ] ); $message->addTo($identity->getEmail()); $this->send($message); $this->em->commit(); } /** * @throws InvalidLinkException */ public function link( string $destination, array $args = [], ?Component $component = null, ?string $mode = null, ): ?string { return $this->linkGenerator->link($destination, $args, $component, $mode); } }