diff --git a/src/Core/Command/RequestPasswordResetHandler.php b/src/Core/Command/RequestPasswordResetHandler.php index e71f2e0730..93598a1351 100644 --- a/src/Core/Command/RequestPasswordResetHandler.php +++ b/src/Core/Command/RequestPasswordResetHandler.php @@ -18,6 +18,7 @@ use Illuminate\Database\Eloquent\ModelNotFoundException; use Flarum\Core; use Flarum\Forum\UrlGenerator; +use Symfony\Component\Translation\TranslatorInterface; class RequestPasswordResetHandler { @@ -41,18 +42,25 @@ class RequestPasswordResetHandler */ protected $url; + /** + * @var TranslatorInterface + */ + protected $translator; + /** * @param UserRepository $users * @param SettingsRepository $settings * @param Mailer $mailer * @param UrlGenerator $url + * @param TranslatorInterface $translator */ - public function __construct(UserRepository $users, SettingsRepository $settings, Mailer $mailer, UrlGenerator $url) + public function __construct(UserRepository $users, SettingsRepository $settings, Mailer $mailer, UrlGenerator $url, TranslatorInterface $translator) { $this->users = $users; $this->settings = $settings; $this->mailer = $mailer; $this->url = $url; + $this->translator = $translator; } /** @@ -72,14 +80,16 @@ public function handle(RequestPasswordReset $command) $token->save(); $data = [ - 'username' => $user->username, - 'url' => $this->url->toRoute('resetPassword', ['token' => $token->id]), - 'forumTitle' => $this->settings->get('forum_title'), + '{username}' => $user->username, + '{url}' => $this->url->toRoute('resetPassword', ['token' => $token->id]), + '{forum}' => $this->settings->get('forum_title'), ]; - $this->mailer->send(['text' => 'flarum::emails.resetPassword'], $data, function (Message $message) use ($user) { + $body = $this->translator->trans('core.email.reset_password.body', $data); + + $this->mailer->raw($body, function (Message $message) use ($user, $data) { $message->to($user->email); - $message->subject('Reset Your Password'); + $message->subject('['.$data['{forum}'].'] '.$this->translator->trans('core.email.reset_password.subject')); }); return $user; diff --git a/src/Core/Listener/EmailConfirmationMailer.php b/src/Core/Listener/EmailConfirmationMailer.php index a79b84d5c6..d34f282ec8 100755 --- a/src/Core/Listener/EmailConfirmationMailer.php +++ b/src/Core/Listener/EmailConfirmationMailer.php @@ -20,6 +20,7 @@ use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Mail\Mailer; use Illuminate\Mail\Message; +use Symfony\Component\Translation\TranslatorInterface; class EmailConfirmationMailer { @@ -32,21 +33,29 @@ class EmailConfirmationMailer * @var Mailer */ protected $mailer; + /** * @var UrlGenerator */ - private $url; + protected $url; + + /** + * @var TranslatorInterface + */ + protected $translator; /** * @param \Flarum\Settings\SettingsRepository $settings * @param Mailer $mailer * @param UrlGenerator $url + * @param TranslatorInterface $translator */ - public function __construct(SettingsRepository $settings, Mailer $mailer, UrlGenerator $url) + public function __construct(SettingsRepository $settings, Mailer $mailer, UrlGenerator $url, TranslatorInterface $translator) { $this->settings = $settings; $this->mailer = $mailer; $this->url = $url; + $this->translator = $translator; } /** @@ -71,9 +80,11 @@ public function whenUserWasRegistered(UserWasRegistered $event) $data = $this->getEmailData($user, $user->email); - $this->mailer->send(['text' => 'flarum::emails.activateAccount'], $data, function (Message $message) use ($user) { + $body = $this->translator->trans('core.email.activate_account.body', $data); + + $this->mailer->raw($body, function (Message $message) use ($user, $data) { $message->to($user->email); - $message->subject('Activate Your New Account'); + $message->subject('['.$data['{forum}'].'] '.$this->translator->trans('core.email.activate_account.subject')); }); } @@ -85,16 +96,17 @@ public function whenUserEmailChangeWasRequested(UserEmailChangeWasRequested $eve $email = $event->email; $data = $this->getEmailData($event->user, $email); - $this->mailer->send(['text' => 'flarum::emails.confirmEmail'], $data, function (Message $message) use ($email) { + $body = $this->translator->trans('core.email.confirm_email.body', $data); + + $this->mailer->raw($body, function (Message $message) use ($email, $data) { $message->to($email); - $message->subject('Confirm Your New Email Address'); + $message->subject('['.$data['{forum}'].'] '.$this->translator->trans('core.email.confirm_email.subject')); }); } /** * @param User $user * @param string $email - * * @return EmailToken */ protected function generateToken(User $user, $email) @@ -110,20 +122,16 @@ protected function generateToken(User $user, $email) * * @param User $user * @param string $email - * * @return array */ protected function getEmailData(User $user, $email) { $token = $this->generateToken($user, $email); - // TODO: Need to use AbstractUrlGenerator, but since this is part of core we - // don't know that the forum routes will be loaded. Should the confirm - // email route be part of core?? return [ - 'username' => $user->username, - 'url' => $this->url->toRoute('confirmEmail', ['token' => $token->id]), - 'forumTitle' => $this->settings->get('forum_title') + '{username}' => $user->username, + '{url}' => $this->url->toRoute('confirmEmail', ['token' => $token->id]), + '{forum}' => $this->settings->get('forum_title') ]; } } diff --git a/src/Forum/Controller/ResetPasswordController.php b/src/Forum/Controller/ResetPasswordController.php index 88345e9d01..07106624be 100644 --- a/src/Forum/Controller/ResetPasswordController.php +++ b/src/Forum/Controller/ResetPasswordController.php @@ -34,8 +34,8 @@ public function __construct(Factory $view) /** * @param Request $request - * @param array $routeParams * @return \Illuminate\Contracts\View\View + * @throws InvalidConfirmationTokenException */ public function render(Request $request) { diff --git a/views/emails/activateAccount.blade.php b/views/emails/activateAccount.blade.php deleted file mode 100644 index 10a235f777..0000000000 --- a/views/emails/activateAccount.blade.php +++ /dev/null @@ -1,8 +0,0 @@ -Hey {{ $username }}! - -Someone (hopefully you!) has signed up to {{ $forumTitle }} with this email address. - -If this was you, simply click the following link and your account will be activated: -{{ $url }} - -If you did not sign up, please ignore this email. diff --git a/views/emails/confirmEmail.blade.php b/views/emails/confirmEmail.blade.php deleted file mode 100644 index 667366ad3a..0000000000 --- a/views/emails/confirmEmail.blade.php +++ /dev/null @@ -1,8 +0,0 @@ -Hey {{ $username }}! - -Someone (hopefully you!) has changed their email address on {{ $forumTitle }} to this one. - -If this was you, simply click the following link and your email will be confirmed: -{{ $url }} - -If this was not you, please ignore this email. diff --git a/views/emails/resetPassword.blade.php b/views/emails/resetPassword.blade.php deleted file mode 100644 index 1f808d99ef..0000000000 --- a/views/emails/resetPassword.blade.php +++ /dev/null @@ -1,8 +0,0 @@ -Hey {{ $username }}! - -Someone (hopefully you!) has submitted a forgotten password request for your account on the {{ $forumTitle }}. - -If this was you, click the following link to reset your password: -{{ $url }} - -If you do not wish to change your password, just ignore this email and nothing will happen.