send verification email after registering
This commit is contained in:
parent
975464efb6
commit
d2d549b657
24
app/Listeners/SendEmailVerification.php
Normal file
24
app/Listeners/SendEmailVerification.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Mail\EmailVerification;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
|
||||
class SendEmailVerification
|
||||
{
|
||||
public function handle(User $user)
|
||||
{
|
||||
if (option('require_verification')) {
|
||||
$url = URL::signedRoute('auth.verify', ['uid' => $user->uid], null, false);
|
||||
|
||||
try {
|
||||
Mail::to($user->email)->send(new EmailVerification(url($url)));
|
||||
} catch (\Exception $e) {
|
||||
report($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -36,5 +36,8 @@ class EventServiceProvider extends ServiceProvider
|
||||
'player.name.updated' => [
|
||||
Listeners\SinglePlayer\UpdateOwnerNickName::class,
|
||||
],
|
||||
'auth.registration.completed' => [
|
||||
Listeners\SendEmailVerification::class,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
31
tests/ListenersTest/SendEmailVerificationTest.php
Normal file
31
tests/ListenersTest/SendEmailVerificationTest.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use App\Mail\EmailVerification;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class SendEmailVerificationTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function testHandle()
|
||||
{
|
||||
Mail::fake();
|
||||
option(['require_verification' => true]);
|
||||
|
||||
$user = factory(User::class)->create(['verified' => false]);
|
||||
Event::dispatch('auth.registration.completed', [$user]);
|
||||
Mail::assertSent(EmailVerification::class, function ($mail) use ($user) {
|
||||
return $mail->hasTo($user->email);
|
||||
});
|
||||
|
||||
Mail::shouldReceive('to')
|
||||
->once()
|
||||
->andThrow(new \Mockery\Exception('A fake exception.'));
|
||||
Event::dispatch('auth.registration.completed', [$user]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user