1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace App\Http\Controllers\Api\Invitation; |
6
|
|
|
|
7
|
|
|
use App\Contracts\Http\Responses\ResponseFactory; |
8
|
|
|
use App\Http\Requests\Api\Invitation\ResendRequest; |
9
|
|
|
use App\Models\User; |
10
|
|
|
use App\Notifications\User\Invitation; |
11
|
|
|
use Illuminate\Auth\Passwords\PasswordBrokerManager; |
12
|
|
|
use Illuminate\Contracts\Auth\PasswordBroker; |
13
|
|
|
use Illuminate\Contracts\Notifications\Dispatcher; |
14
|
|
|
use Illuminate\Http\Response; |
15
|
|
|
|
16
|
|
|
final class Resend |
17
|
|
|
{ |
18
|
|
|
private Dispatcher $notificationDispatcher; |
19
|
|
|
|
20
|
|
|
private PasswordBrokerManager $passwordBrokerManager; |
21
|
|
|
|
22
|
|
|
private ResponseFactory $responseFactory; |
23
|
|
|
|
24
|
|
|
public function __construct( |
25
|
|
|
Dispatcher $notificationDispatcher, |
26
|
|
|
PasswordBrokerManager $passwordBrokerManager, |
27
|
|
|
ResponseFactory $responseFactory |
28
|
|
|
) { |
29
|
|
|
$this->notificationDispatcher = $notificationDispatcher; |
30
|
|
|
$this->passwordBrokerManager = $passwordBrokerManager; |
31
|
|
|
$this->responseFactory = $responseFactory; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function __invoke(ResendRequest $request): Response |
35
|
|
|
{ |
36
|
|
|
$user = User::query()->where('email', $request->input('email'))->first(); |
37
|
|
|
|
38
|
|
|
if ($user instanceof User) { |
39
|
|
|
$this->notificationDispatcher->send($user, |
40
|
|
|
new Invitation($this->getPasswordBroker()->createToken($user)) |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $this->responseFactory->noContent(Response::HTTP_OK); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
private function getPasswordBroker(): PasswordBroker |
48
|
|
|
{ |
49
|
|
|
return $this->passwordBrokerManager->broker('user-invitations'); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|