|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Auth; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
6
|
|
|
use App\Http\Requests\Request; |
|
7
|
|
|
use App\Repositories\UserRepository; |
|
8
|
|
|
use Illuminate\Foundation\Auth\SendsPasswordResetEmails; |
|
9
|
|
|
use Illuminate\Support\Facades\Password; |
|
10
|
|
|
|
|
11
|
|
|
class ForgotPasswordController extends Controller |
|
12
|
|
|
{ |
|
13
|
|
|
/* |
|
14
|
|
|
|-------------------------------------------------------------------------- |
|
15
|
|
|
| Password Reset Controller |
|
16
|
|
|
|-------------------------------------------------------------------------- |
|
17
|
|
|
| |
|
18
|
|
|
| This controller is responsible for handling password reset emails and |
|
19
|
|
|
| includes a trait which assists in sending these notifications from |
|
20
|
|
|
| your application to your users. Feel free to explore this trait. |
|
21
|
|
|
| |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
use SendsPasswordResetEmails; |
|
25
|
|
|
|
|
26
|
|
|
const PASSWORD_EMAIL = 'passwords.email'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Create a new controller instance. |
|
30
|
|
|
* |
|
31
|
|
|
* @return void |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->middleware('guest'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Send a reset link to the given user. |
|
40
|
|
|
* |
|
41
|
|
|
* @param Request $request |
|
42
|
|
|
* |
|
43
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
|
44
|
|
|
*/ |
|
45
|
|
|
public function sendResetLinkEmail(Request $request) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->validateEmail($request); |
|
48
|
|
|
|
|
49
|
|
|
if ($this->hasManyUser($request->input('email')) > 1) { |
|
50
|
|
|
return $this->sendResetLinkFailedResponse($request, static::PASSWORD_EMAIL); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
// We will send the password reset link to this user. Once we have attempted |
|
54
|
|
|
// to send the link, we will examine the response then see the message we |
|
55
|
|
|
// need to show to the user. Finally, we'll send out a proper response. |
|
56
|
|
|
$response = $this->broker()->sendResetLink( |
|
57
|
|
|
$request->only('email') |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
|
|
return $response === Password::RESET_LINK_SENT |
|
61
|
|
|
? $this->sendResetLinkResponse($request, $response) |
|
62
|
|
|
: $this->sendResetLinkFailedResponse($request, $response); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
private function hasManyUser($email) |
|
66
|
|
|
{ |
|
67
|
|
|
return app(UserRepository::class)->findWhere(['email' => $email])->count(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function showLinkRequestForm() |
|
71
|
|
|
{ |
|
72
|
|
|
return view('web.auth.passwords.email'); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|