-
-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor AccountActivationMailer and SendConfirmationEmailController (#…
…2493) * Add AccountActivationMailerTrait and use in AccountActivationMailer and SendConfirmationEmailController * Remove prefix Co-authored-by: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com>
- Loading branch information
1 parent
fe8dda6
commit 374189d
Showing
3 changed files
with
67 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Flarum\User; | ||
|
||
use Flarum\Mail\Job\SendRawEmailJob; | ||
|
||
trait AccountActivationMailerTrait | ||
{ | ||
/** | ||
* @param User $user | ||
* @param string $email | ||
* @return EmailToken | ||
*/ | ||
protected function generateToken(User $user, $email) | ||
{ | ||
$token = EmailToken::generate($email, $user->id); | ||
$token->save(); | ||
|
||
return $token; | ||
} | ||
|
||
/** | ||
* Get the data that should be made available to email templates. | ||
* | ||
* @param User $user | ||
* @param EmailToken $token | ||
* @return array | ||
*/ | ||
protected function getEmailData(User $user, EmailToken $token) | ||
{ | ||
return [ | ||
'{username}' => $user->display_name, | ||
'{url}' => $this->url->to('forum')->route('confirmEmail', ['token' => $token->token]), | ||
'{forum}' => $this->settings->get('forum_title') | ||
]; | ||
} | ||
|
||
/** | ||
* @param User $user | ||
* @param array $data | ||
*/ | ||
protected function sendConfirmationEmail(User $user, $data) | ||
{ | ||
$body = $this->translator->trans('core.email.activate_account.body', $data); | ||
$subject = $this->translator->trans('core.email.activate_account.subject'); | ||
|
||
$this->queue->push(new SendRawEmailJob($user->email, $subject, $body)); | ||
} | ||
} |