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 (is_null($user->confirmed_at)) { |
34
|
|
|
throw ValidationException::withMessages([ |
35
|
|
|
'confirmation' => [ |
36
|
|
|
__('confirmation::confirmation.not_confirmed_reset_password', [ |
37
|
|
|
'resend_link' => route('auth.resend_confirmation') |
38
|
|
|
]) |
39
|
|
|
] |
40
|
|
|
]); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
// We will send the password reset link to this user. Once we have attempted |
44
|
|
|
// to send the link, we will examine the response then see the message we |
45
|
|
|
// need to show to the user. Finally, we'll send out a proper response. |
46
|
|
|
$response = $this->broker()->sendResetLink( |
47
|
|
|
$request->only('email') |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
return $response == Password::RESET_LINK_SENT |
51
|
|
|
? $this->sendResetLinkResponse($response) |
52
|
|
|
: $this->sendResetLinkFailedResponse($request, $response); |
53
|
|
|
} |
54
|
|
|
} |