Files
monica/app/Notifications/ConfirmEmail.php
T
2019-10-27 23:37:45 +01:00

82 lines
2.0 KiB
PHP

<?php
namespace App\Notifications;
use App\Models\User\User;
use Illuminate\Bus\Queueable;
use App\Models\Account\Account;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\URL;
use App\Interfaces\MailNotification;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification as LaravelNotification;
class ConfirmEmail extends LaravelNotification implements ShouldQueue, MailNotification
{
use Dispatchable, InteractsWithQueue, Queueable;
/**
* @var bool
*/
public $force;
public function __construct($force = false)
{
$this->force = $force;
}
/**
* Get the notification's delivery channels.
*
* @return array
*/
public function via()
{
if (! $this->force) {
/** @var int $count */
$count = Account::count();
if (! config('monica.signup_double_optin') || $count == 1) {
return [];
}
}
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param User $user
* @return MailMessage
*/
public function toMail(User $user) : MailMessage
{
App::setLocale($user->locale);
return (new MailMessage)
->subject(trans('mail.confirmation_email_title'))
->line(trans('mail.confirmation_email_title'))
->line(trans('mail.confirmation_email_intro'))
->action(
trans('mail.confirmation_email_button'),
$this->verificationUrl($user)
);
}
/**
* Get the verification URL for the given notifiable.
*
* @param mixed $notifiable
* @return string
*/
protected function verificationUrl($notifiable)
{
return URL::temporarySignedRoute(
'verification.verify', now()->addMinutes(60), ['id' => $notifiable->getKey()]
);
}
}