Slide 72
Slide 72 text
App User
App\Models\User
Eloquent Model
と Notifiable
への依存がなくなった!
Respository
と Notifier
のインターフェースにのみ依存
use Domain\User\UserId;
use Domain\User\UserNotifier;
use Domain\User\UserRepository;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Contracts\Auth\MustVerifyEmail as MustVerifyEmailContract;
use Illuminate\Foundation\Auth\Access\Authorizable;
class User implements
AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract,
MustVerifyEmailContract
{
use Authorizable;
private UserId $id;
private UserRepository $repository;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class User implements
AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract,
MustVerifyEmailContract
use Domain\User\UserId;
1
use Domain\User\UserNotifier;
2
use Domain\User\UserRepository;
3
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
4
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
5
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
6
use Illuminate\Contracts\Auth\MustVerifyEmail as MustVerifyEmailContract;
7
use Illuminate\Foundation\Auth\Access\Authorizable;
8
9
10
11
12
13
14
{
15
use Authorizable;
16
17
private UserId $id;
18
private UserRepository $repository;
19
private UserId $id;
private UserRepository $repository;
use Domain\User\UserId;
1
use Domain\User\UserNotifier;
2
use Domain\User\UserRepository;
3
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
4
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
5
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
6
use Illuminate\Contracts\Auth\MustVerifyEmail as MustVerifyEmailContract;
7
use Illuminate\Foundation\Auth\Access\Authorizable;
8
9
class User implements
10
AuthenticatableContract,
11
AuthorizableContract,
12
CanResetPasswordContract,
13
MustVerifyEmailContract
14
{
15
use Authorizable;
16
17
18
19
use Domain\User\UserId;
1
use Domain\User\UserNotifier;
2
use Domain\User\UserRepository;
3
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
4
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
5
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
6
use Illuminate\Contracts\Auth\MustVerifyEmail as MustVerifyEmailContract;
7
use Illuminate\Foundation\Auth\Access\Authorizable;
8
9
class User implements
10
AuthenticatableContract,
11
AuthorizableContract,
12
CanResetPasswordContract,
13
MustVerifyEmailContract
14
{
15
use Authorizable;
16
17
private UserId $id;
18
private UserRepository $repository;
19
use Domain\User\UserId;
1
use Domain\User\UserNotifier;
2
use Domain\User\UserRepository;
3
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
4
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
5
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
6
use Illuminate\Contracts\Auth\MustVerifyEmail as MustVerifyEmailContract;
7
use Illuminate\Foundation\Auth\Access\Authorizable;
8
9
class User implements
10
AuthenticatableContract,
11
AuthorizableContract,
12
CanResetPasswordContract,
13
MustVerifyEmailContract
14
{
15
use Authorizable;
16
17
private UserId $id;
18
private UserRepository $repository;
19
use Domain\User\UserId;
1
use Domain\User\UserNotifier;
2
use Domain\User\UserRepository;
3
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
4
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
5
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
6
use Illuminate\Contracts\Auth\MustVerifyEmail as MustVerifyEmailContract;
7
use Illuminate\Foundation\Auth\Access\Authorizable;
8
9
class User implements
10
AuthenticatableContract,
11
AuthorizableContract,
12
CanResetPasswordContract,
13
MustVerifyEmailContract
14
{
15
use Authorizable;
16
17
private UserId $id;
18
private UserRepository $repository;
19
'id' => $this->id->rawValue(),
{
46
$user = $this->repository->get($this->id);
47
$url = $this->createVerificationUrl();
48
49
$this->notifier->sendEmailVerificationNotification($user, $url);
50
}
51
52
private function createVerificationUrl(): string
53
{
54
return URL::temporarySignedRoute(
55
'verification.verify',
56
Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)),
57
[
58
59
'hash' => sha1($this->getEmailForVerification()),
60
]
61
);
62
}
63