1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace App\Http\Controllers\Api\Invitation; |
6
|
|
|
|
7
|
|
|
use App\Http\Requests\Api\Invitation\AcceptRequest; |
8
|
|
|
use App\Models\User; |
9
|
|
|
use Illuminate\Auth\Events\PasswordReset; |
|
|
|
|
10
|
|
|
use Illuminate\Auth\Passwords\PasswordBrokerManager; |
|
|
|
|
11
|
|
|
use Illuminate\Contracts\Auth\PasswordBroker; |
|
|
|
|
12
|
|
|
use Illuminate\Contracts\Events\Dispatcher; |
|
|
|
|
13
|
|
|
use Illuminate\Contracts\Hashing\Hasher; |
|
|
|
|
14
|
|
|
use Illuminate\Contracts\Routing\ResponseFactory; |
|
|
|
|
15
|
|
|
use Illuminate\Contracts\Translation\Translator; |
|
|
|
|
16
|
|
|
use Illuminate\Support\Str; |
|
|
|
|
17
|
|
|
|
18
|
|
|
final class Accept |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var \Illuminate\Auth\Passwords\PasswordBrokerManager |
22
|
|
|
*/ |
23
|
|
|
protected $passwordBrokerManager; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var \Illuminate\Contracts\Hashing\Hasher |
27
|
|
|
*/ |
28
|
|
|
protected $hasher; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var \Illuminate\Contracts\Events\Dispatcher |
32
|
|
|
*/ |
33
|
|
|
protected $eventDispatcher; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var \Illuminate\Contracts\Routing\ResponseFactory |
37
|
|
|
*/ |
38
|
|
|
protected $responseFactory; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var \Illuminate\Contracts\Translation\Translator |
42
|
|
|
*/ |
43
|
|
|
protected $translator; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Reset constructor. |
47
|
|
|
* |
48
|
|
|
* @param \Illuminate\Auth\Passwords\PasswordBrokerManager $passwordBrokerManager |
49
|
|
|
* @param \Illuminate\Contracts\Hashing\Hasher $hasher |
50
|
|
|
* @param \Illuminate\Contracts\Events\Dispatcher $eventDispatcher |
51
|
|
|
* @param \Illuminate\Contracts\Routing\ResponseFactory $responseFactory |
52
|
|
|
* @param \Illuminate\Contracts\Translation\Translator $translator |
53
|
|
|
*/ |
54
|
|
|
public function __construct( |
55
|
|
|
PasswordBrokerManager $passwordBrokerManager, |
56
|
|
|
Hasher $hasher, |
57
|
|
|
Dispatcher $eventDispatcher, |
58
|
|
|
ResponseFactory $responseFactory, |
59
|
|
|
Translator $translator |
60
|
|
|
) { |
61
|
|
|
$this->passwordBrokerManager = $passwordBrokerManager; |
62
|
|
|
$this->hasher = $hasher; |
63
|
|
|
$this->eventDispatcher = $eventDispatcher; |
64
|
|
|
$this->responseFactory = $responseFactory; |
65
|
|
|
$this->translator = $translator; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param \App\Http\Requests\Api\Invitation\AcceptRequest $request |
70
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
|
|
|
71
|
|
|
*/ |
72
|
|
|
public function __invoke(AcceptRequest $request) |
73
|
|
|
{ |
74
|
|
|
$credentials = $request->only(['token', 'email', 'password', 'password_confirmation']); |
75
|
|
|
|
76
|
|
|
$response = $this->getPasswordBroker()->reset($credentials, function (User $user, string $password) { |
77
|
|
|
$user->setAttribute('password', $this->hasher->make($password)); |
78
|
|
|
|
79
|
|
|
$user->setRememberToken(Str::random(60)); |
80
|
|
|
|
81
|
|
|
$user->save(); |
82
|
|
|
|
83
|
|
|
$this->eventDispatcher->dispatch(new PasswordReset($user)); |
84
|
|
|
}); |
85
|
|
|
|
86
|
|
|
if (PasswordBroker::PASSWORD_RESET === $response) { |
87
|
|
|
return $this->responseFactory->json([ |
88
|
|
|
'message' => $this->translator->trans($response), |
89
|
|
|
], 200); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return $this->responseFactory->json([ |
93
|
|
|
'message' => $this->translator->trans(PasswordBroker::INVALID_TOKEN), |
94
|
|
|
], 400); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return \Illuminate\Contracts\Auth\PasswordBroker |
99
|
|
|
*/ |
100
|
|
|
protected function getPasswordBroker(): PasswordBroker |
101
|
|
|
{ |
102
|
|
|
return $this->passwordBrokerManager->broker('user-invitations'); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths