settings = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS); } /** * Sends an email with an absolute link including the given forgot hash to the passed user * with instructions to recover the account. * * @throws TransportExceptionInterface */ public function sendRecoveryEmail(RequestInterface $request, array $userData, string $hash): void { $receiver = new Address($userData['email'], $this->getReceiverName($userData)); $email = $this->prepareMail($request, $receiver, $hash, $userData); $event = new SendRecoveryEmailEvent($email, $userData); $this->eventDispatcher->dispatch($event); $this->mailer->send($event->getEmail()); } /** * Get display name from values. Fallback to username if none of the "_name" fields is set. */ protected function getReceiverName(array $userInformation): string { $displayName = trim( sprintf( '%s%s%s', $userInformation['first_name'], $userInformation['middle_name'] ? " {$userInformation['middle_name']}" : '', $userInformation['last_name'] ? " {$userInformation['last_name']}" : '' ) ); return $displayName ? $displayName . ' (' . $userInformation['username'] . ')' : $userInformation['username']; } /** * Create email object from configuration. */ protected function prepareMail(RequestInterface $request, Address $receiver, string $hash, array $userData): FluidEmail { $url = $this->uriBuilder ->reset() ->setRequest($request) ->setCreateAbsoluteUri(true) ->uriFor( 'showChangePassword', ['hash' => $hash], 'PasswordRecovery', 'felogin', 'Login' ); $variables = [ 'receiverName' => $receiver->getName(), 'userData' => $userData, 'url' => $url, 'validUntil' => date($this->settings['dateFormat'] ?? 'Y-m-d H:i', $this->recoveryConfiguration->getLifeTimeTimestamp()), ]; $mail = $this->templatedEmailFactory->createWithOverrides( $this->settings['email']['templateRootPaths'] ?? [], $this->settings['email']['layoutRootPaths'] ?? [], $this->settings['email']['partialRootPaths'] ?? [], $request, ); $mail->subject($this->getEmailSubject()) ->from($this->recoveryConfiguration->getSender()) ->to($receiver) ->assignMultiple($variables) ->setTemplate($this->recoveryConfiguration->getMailTemplateName()); $replyTo = $this->recoveryConfiguration->getReplyTo(); if ($replyTo) { $mail->addReplyTo($replyTo); } return $mail; } protected function getEmailSubject(): string { return LocalizationUtility::translate('password_recovery_mail_header', 'felogin'); } }