|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BeyondCode\EmailConfirmation\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use Illuminate\Support\Facades\Password; |
|
7
|
|
|
use Illuminate\Validation\ValidationException; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Trait SendsPasswordResetEmails |
|
11
|
|
|
* @package BeyondCode\EmailConfirmation\Traits |
|
12
|
|
|
*/ |
|
13
|
|
|
trait SendsPasswordResetEmails |
|
14
|
|
|
{ |
|
15
|
|
|
use \Illuminate\Foundation\Auth\SendsPasswordResetEmails; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Send a reset link to the given user. |
|
19
|
|
|
* |
|
20
|
|
|
* @param Request $request |
|
21
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
|
22
|
|
|
* @throws ValidationException |
|
23
|
|
|
*/ |
|
24
|
|
|
public function sendResetLinkEmail(Request $request) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->validateEmail($request); |
|
27
|
|
|
|
|
28
|
|
|
$user = $this->broker()->getUser($request->only('email')); |
|
29
|
|
|
|
|
30
|
|
|
// If the user hasn't confirmed their email address, |
|
31
|
|
|
// we will throw a validation exception for this error. |
|
32
|
|
|
// A user can not request a password reset link if they are not confirmed. |
|
33
|
|
|
if ($user && is_null($user->confirmed_at)) { |
|
34
|
|
|
|
|
35
|
|
|
session(['confirmation_user_id' => $user->getKey()]); |
|
36
|
|
|
|
|
37
|
|
|
throw ValidationException::withMessages([ |
|
38
|
|
|
'confirmation' => [ |
|
39
|
|
|
__('confirmation::confirmation.not_confirmed_reset_password', [ |
|
40
|
|
|
'resend_link' => route('auth.resend_confirmation') |
|
41
|
|
|
]) |
|
42
|
|
|
] |
|
43
|
|
|
]); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
// We will send the password reset link to this user. Once we have attempted |
|
47
|
|
|
// to send the link, we will examine the response then see the message we |
|
48
|
|
|
// need to show to the user. Finally, we'll send out a proper response. |
|
49
|
|
|
$response = $this->broker()->sendResetLink( |
|
50
|
|
|
$request->only('email') |
|
51
|
|
|
); |
|
52
|
|
|
|
|
53
|
|
|
return $response == Password::RESET_LINK_SENT |
|
54
|
|
|
? $this->sendResetLinkResponse($response) |
|
|
|
|
|
|
55
|
|
|
: $this->sendResetLinkFailedResponse($request, $response); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
This check looks for function calls that miss required arguments.