diff --git a/core/Service/Auth/AuthServicesFactory.php b/core/Service/Auth/AuthServicesFactory.php index d2277f9..6dd4cb8 100644 --- a/core/Service/Auth/AuthServicesFactory.php +++ b/core/Service/Auth/AuthServicesFactory.php @@ -59,7 +59,9 @@ class AuthServicesFactory $this->authRepositoryFactory->createPasswordResetRepository(), $this->userServicesFactory->createUserPasswordService(), $this->createRememberMeService(), - $this->mailServicesFactory->createMailService() + $this->mailServicesFactory->createMailService(), + appTitle(), + appUrl(), ); } @@ -69,7 +71,9 @@ class AuthServicesFactory $this->userServicesFactory->createUserReadRepository(), $this->userServicesFactory->createUserWriteRepository(), $this->authRepositoryFactory->createEmailVerificationRepository(), - $this->mailServicesFactory->createMailService() + $this->mailServicesFactory->createMailService(), + appTitle(), + appUrl(), ); } diff --git a/core/Service/Auth/EmailVerificationService.php b/core/Service/Auth/EmailVerificationService.php index bc8ab3a..05ef3de 100644 --- a/core/Service/Auth/EmailVerificationService.php +++ b/core/Service/Auth/EmailVerificationService.php @@ -19,10 +19,25 @@ class EmailVerificationService private readonly UserReadRepositoryInterface $userReadRepository, private readonly UserWriteRepositoryInterface $userWriteRepository, private readonly EmailVerificationRepositoryInterface $emailVerificationRepository, - private readonly MailService $mailService + private readonly MailService $mailService, + private readonly string $appTitle = '', + private readonly string $appUrl = '', ) { } + private function resolveAppTitle(): string + { + return $this->appTitle !== '' ? $this->appTitle : appTitle(); + } + + private function resolveAppUrl(string $path = ''): string + { + if ($this->appUrl !== '') { + return rtrim($this->appUrl, '/') . ($path !== '' ? '/' . ltrim($path, '/') : ''); + } + return appUrl($path); + } + public function sendVerification(int $userId, ?string $locale = null): array { $user = $this->userReadRepository->find($userId); @@ -55,17 +70,17 @@ class EmailVerificationService } $greeting .= ','; $verifyPath = Request::withLocale('verify-email', $locale); - $verifyUrl = appUrl($verifyPath); + $verifyUrl = $this->resolveAppUrl($verifyPath); $previousLocale = I18n::$locale ?? null; I18n::$locale = $locale; $subject = t('Email verification code'); I18n::$locale = $previousLocale; $vars = [ - 'app_name' => appTitle(), + 'app_name' => $this->resolveAppTitle(), 'app_logo_url' => appLogoUrlAbsolute(128), - 'imprint_url' => appUrl(Request::withLocale('imprint', $locale)), - 'privacy_url' => appUrl(Request::withLocale('privacy', $locale)), + 'imprint_url' => $this->resolveAppUrl(Request::withLocale('imprint', $locale)), + 'privacy_url' => $this->resolveAppUrl(Request::withLocale('privacy', $locale)), 'code' => $code, 'expires_minutes' => self::EXPIRY_MINUTES, 'verify_url' => $verifyUrl, diff --git a/core/Service/Auth/PasswordResetService.php b/core/Service/Auth/PasswordResetService.php index cd45b05..ef5dde5 100644 --- a/core/Service/Auth/PasswordResetService.php +++ b/core/Service/Auth/PasswordResetService.php @@ -20,10 +20,25 @@ class PasswordResetService private readonly PasswordResetRepositoryInterface $passwordResetRepository, private readonly UserPasswordService $userPasswordService, private readonly RememberMeService $rememberMeService, - private readonly MailService $mailService + private readonly MailService $mailService, + private readonly string $appTitle = '', + private readonly string $appUrl = '', ) { } + private function resolveAppTitle(): string + { + return $this->appTitle !== '' ? $this->appTitle : appTitle(); + } + + private function resolveAppUrl(string $path = ''): string + { + if ($this->appUrl !== '') { + return rtrim($this->appUrl, '/') . ($path !== '' ? '/' . ltrim($path, '/') : ''); + } + return appUrl($path); + } + public function requestReset(string $email, ?string $locale = null): array { $email = trim($email); @@ -58,17 +73,17 @@ class PasswordResetService } $greeting .= ','; $verifyPath = Request::withLocale('password/verify', $locale); - $verifyUrl = appUrl($verifyPath); + $verifyUrl = $this->resolveAppUrl($verifyPath); $previousLocale = I18n::$locale ?? null; I18n::$locale = $locale; $subject = t('Password reset code'); I18n::$locale = $previousLocale; $vars = [ - 'app_name' => appTitle(), + 'app_name' => $this->resolveAppTitle(), 'app_logo_url' => appLogoUrlAbsolute(128), - 'imprint_url' => appUrl(Request::withLocale('imprint', $locale)), - 'privacy_url' => appUrl(Request::withLocale('privacy', $locale)), + 'imprint_url' => $this->resolveAppUrl(Request::withLocale('imprint', $locale)), + 'privacy_url' => $this->resolveAppUrl(Request::withLocale('privacy', $locale)), 'code' => $code, 'expires_minutes' => self::EXPIRY_MINUTES, 'verify_url' => $verifyUrl,