mirror of
https://github.com/flarum/framework.git
synced 2024-12-12 06:03:39 +08:00
parent
f47be34df0
commit
c0bf875890
|
@ -18,6 +18,7 @@ use Illuminate\Mail\Message;
|
|||
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 @@ class RequestPasswordResetHandler
|
|||
$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;
|
||||
|
|
|
@ -20,6 +20,7 @@ use Flarum\Settings\SettingsRepository;
|
|||
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 @@ class EmailConfirmationMailer
|
|||
|
||||
$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 @@ class EmailConfirmationMailer
|
|||
$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 @@ class EmailConfirmationMailer
|
|||
*
|
||||
* @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')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ class ResetPasswordController extends AbstractHtmlController
|
|||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param array $routeParams
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @throws InvalidConfirmationTokenException
|
||||
*/
|
||||
public function render(Request $request)
|
||||
{
|
||||
|
|
|
@ -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.
|
|
@ -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.
|
|
@ -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.
|
Loading…
Reference in New Issue
Block a user