1
|
|
|
<?php namespace App\Http\Controllers\Users; |
2
|
|
|
|
3
|
|
|
use App\Contracts\Registrar; |
4
|
|
|
use App\Exceptions\Users\TokenNotValidException; |
5
|
|
|
use App\Http\Controllers\Controller; |
6
|
|
|
use Illuminate\Contracts\Auth\PasswordBroker; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
|
9
|
|
|
class PasswordController extends Controller |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Create a new password controller instance. |
13
|
|
|
*/ |
14
|
16 |
|
public function __construct() |
15
|
|
|
{ |
16
|
16 |
|
$this->middleware('guest'); |
17
|
16 |
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Display the form to request a password reset link. |
21
|
|
|
* |
22
|
|
|
* @param \Illuminate\Http\Request $request |
23
|
|
|
* |
24
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\View\View|\Illuminate\Contracts\View\Factory |
25
|
|
|
*/ |
26
|
5 |
|
public function getEmail(Request $request) |
27
|
|
|
{ |
28
|
5 |
|
if ($request->ajax() || $request->wantsJson()) { |
29
|
|
|
return response()->json([]); |
30
|
|
|
} |
31
|
|
|
|
32
|
5 |
|
return view('password/email'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Send a password reset link to the given email's owner, via email. |
37
|
|
|
* |
38
|
|
|
* @param \Illuminate\Http\Request $request |
39
|
|
|
* @param \App\Contracts\Registrar $registrar |
40
|
|
|
* |
41
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
42
|
|
|
*/ |
43
|
4 |
|
public function postEmail(Request $request, Registrar $registrar) |
44
|
|
|
{ |
45
|
4 |
|
$registrar->sendResetPasswordLinkViaEmail(); |
46
|
|
|
|
47
|
2 |
|
if ($request->ajax() || $request->wantsJson()) { |
48
|
1 |
|
return response()->json(['message' => trans('passwords.sent')]); |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
return redirect()->back()->with('message', trans('passwords.sent')); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Display the password reset view for the given token. |
56
|
|
|
* |
57
|
|
|
* @param \Illuminate\Http\Request $request |
58
|
|
|
* @param string $token |
59
|
|
|
* |
60
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\View\View|\Illuminate\Contracts\View\Factory |
61
|
|
|
*/ |
62
|
7 |
|
public function getReset(Request $request, $token = null) |
63
|
|
|
{ |
64
|
7 |
|
if (is_null($token)) { |
65
|
1 |
|
if ($request->ajax() || $request->wantsJson()) { |
66
|
|
|
throw new TokenNotValidException(); |
67
|
|
|
} |
68
|
|
|
|
69
|
1 |
|
return view('password/reset')->withErrors(['token' => trans(PasswordBroker::INVALID_TOKEN)]); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
6 |
|
if ($request->ajax() || $request->wantsJson()) { |
73
|
|
|
return response()->json(['token' => $token]); |
74
|
|
|
} |
75
|
|
|
|
76
|
6 |
|
return view('password/reset')->with('token', $token); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Reset the password through password-reset-token and email provided. |
81
|
|
|
* |
82
|
|
|
* @param \Illuminate\Http\Request $request |
83
|
|
|
* @param \App\Contracts\Registrar $registrar |
84
|
|
|
* |
85
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
86
|
|
|
*/ |
87
|
8 |
|
public function postReset(Request $request, Registrar $registrar) |
88
|
|
|
{ |
89
|
8 |
|
$registrar->resetPassword(); |
90
|
|
|
|
91
|
2 |
|
if ($request->ajax() || $request->wantsJson()) { |
92
|
1 |
|
return response()->json(['message' => trans('passwords.reset')]); |
93
|
|
|
} |
94
|
|
|
|
95
|
1 |
|
return redirect($this->redirectPath())->with('message', trans('passwords.reset')); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get the post-register/-login redirect path. |
100
|
|
|
* |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
1 |
|
private function redirectPath() |
104
|
|
|
{ |
105
|
1 |
|
if (isset($this->redirectPath)) { |
106
|
|
|
return $this->redirectPath; |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
1 |
|
return isset($this->redirectTo) ? $this->redirectTo : '/login'; |
|
|
|
|
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: