回答編集履歴
4
追記
test
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
|
1
|
+
![イメージ説明](44a5762419f3de09205539c3c164a2fa.png)
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
% php artisan route:list | grep ResetPasswordController
|
8
|
-
|
9
|
-
| | POST | password/reset | password.update | App\Http\Controllers\Auth\ResetPasswordController@reset | web |
|
10
|
-
|
11
|
-
| | GET|HEAD | password/reset/{token} | password.reset | App\Http\Controllers\Auth\ResetPasswordController@showResetForm | web |
|
12
|
-
|
13
|
-
```
|
5
|
+
Form の送信先が /password/email であることがわかる
|
14
6
|
|
15
7
|
|
16
8
|
|
9
|
+
`php artisan route:list | grep password/email` でコントローラーを特定する
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
![イメージ説明](d7665719ac7d814858d4a0c1a01e6df2.png)
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
-
`
|
17
|
+
`App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail` だとわかる
|
18
18
|
|
19
19
|
|
20
20
|
|
@@ -30,13 +30,11 @@
|
|
30
30
|
|
31
31
|
use App\Http\Controllers\Controller;
|
32
32
|
|
33
|
-
use App\Providers\RouteServiceProvider;
|
34
|
-
|
35
|
-
use Illuminate\Foundation\Auth\
|
33
|
+
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
36
34
|
|
37
35
|
|
38
36
|
|
39
|
-
class
|
37
|
+
class ForgotPasswordController extends Controller
|
40
38
|
|
41
39
|
{
|
42
40
|
|
@@ -50,11 +48,11 @@
|
|
50
48
|
|
51
49
|
|
|
52
50
|
|
53
|
-
| This controller is responsible for handling password reset
|
51
|
+
| This controller is responsible for handling password reset emails and
|
54
52
|
|
55
|
-
|
|
53
|
+
| includes a trait which assists in sending these notifications from
|
56
54
|
|
57
|
-
|
|
55
|
+
| your application to your users. Feel free to explore this trait.
|
58
56
|
|
59
57
|
|
|
60
58
|
|
@@ -62,21 +60,7 @@
|
|
62
60
|
|
63
61
|
|
64
62
|
|
65
|
-
use
|
63
|
+
use SendsPasswordResetEmails;
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
/**
|
70
|
-
|
71
|
-
* Where to redirect users after resetting their password.
|
72
|
-
|
73
|
-
*
|
74
|
-
|
75
|
-
* @var string
|
76
|
-
|
77
|
-
*/
|
78
|
-
|
79
|
-
protected $redirectTo = RouteServiceProvider::HOME;
|
80
64
|
|
81
65
|
}
|
82
66
|
|
@@ -84,7 +68,7 @@
|
|
84
68
|
|
85
69
|
|
86
70
|
|
87
|
-
t
|
71
|
+
`SendsPasswordResetEmails` にメソッドがありそう
|
88
72
|
|
89
73
|
|
90
74
|
|
@@ -98,35 +82,43 @@
|
|
98
82
|
|
99
83
|
|
100
84
|
|
101
|
-
use Illuminate\Auth\Events\PasswordReset;
|
102
|
-
|
103
85
|
use Illuminate\Http\JsonResponse;
|
104
86
|
|
105
87
|
use Illuminate\Http\Request;
|
106
88
|
|
107
|
-
use Illuminate\Support\Facades\Auth;
|
108
|
-
|
109
|
-
use Illuminate\Support\Facades\Hash;
|
110
|
-
|
111
89
|
use Illuminate\Support\Facades\Password;
|
112
|
-
|
113
|
-
use Illuminate\Support\Str;
|
114
90
|
|
115
91
|
use Illuminate\Validation\ValidationException;
|
116
92
|
|
117
93
|
|
118
94
|
|
119
|
-
trait
|
95
|
+
trait SendsPasswordResetEmails
|
120
96
|
|
121
97
|
{
|
122
98
|
|
99
|
+
/**
|
100
|
+
|
101
|
+
* Display the form to request a password reset link.
|
102
|
+
|
103
|
+
*
|
104
|
+
|
123
|
-
u
|
105
|
+
* @return \Illuminate\View\View
|
106
|
+
|
107
|
+
*/
|
108
|
+
|
109
|
+
public function showLinkRequestForm()
|
110
|
+
|
111
|
+
{
|
112
|
+
|
113
|
+
return view('auth.passwords.email');
|
114
|
+
|
115
|
+
}
|
124
116
|
|
125
117
|
|
126
118
|
|
127
119
|
/**
|
128
120
|
|
129
|
-
*
|
121
|
+
* Send a reset link to the given user.
|
130
122
|
|
131
123
|
*
|
132
124
|
|
@@ -136,137 +128,39 @@
|
|
136
128
|
|
137
129
|
*/
|
138
130
|
|
139
|
-
public function
|
131
|
+
public function sendResetLinkEmail(Request $request)
|
140
132
|
|
141
133
|
{
|
142
134
|
|
143
|
-
$
|
135
|
+
$this->validateEmail($request);
|
144
136
|
|
145
137
|
|
146
138
|
|
147
|
-
//
|
139
|
+
// We will send the password reset link to this user. Once we have attempted
|
148
140
|
|
149
|
-
// will
|
141
|
+
// to send the link, we will examine the response then see the message we
|
150
142
|
|
151
|
-
// d
|
143
|
+
// need to show to the user. Finally, we'll send out a proper response.
|
152
144
|
|
153
|
-
$response = $this->broker()->
|
145
|
+
$response = $this->broker()->sendResetLink(
|
154
146
|
|
155
|
-
$this->credentials($request), function ($user, $password) {
|
156
|
-
|
157
|
-
|
147
|
+
$this->credentials($request)
|
158
|
-
|
159
|
-
}
|
160
148
|
|
161
149
|
);
|
162
150
|
|
163
151
|
|
164
152
|
|
165
|
-
|
153
|
+
return $response == Password::RESET_LINK_SENT
|
166
154
|
|
167
|
-
|
155
|
+
? $this->sendResetLinkResponse($request, $response)
|
168
156
|
|
169
|
-
// redirect them back to where they came from with their error message.
|
170
|
-
|
171
|
-
return $response == Password::PASSWORD_RESET
|
172
|
-
|
173
|
-
? $this->sendResetResponse($request, $response) // 多分ここだと推測できる
|
174
|
-
|
175
|
-
: $this->sendResetFailedResponse($request, $response);
|
157
|
+
: $this->sendResetLinkFailedResponse($request, $response);
|
176
158
|
|
177
159
|
}
|
178
160
|
|
179
|
-
略
|
180
|
-
|
181
|
-
```
|
182
161
|
|
183
162
|
|
184
|
-
|
185
|
-
`sendResetResponse()` の実装を見る
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
```php
|
190
|
-
|
191
|
-
/**
|
192
|
-
|
193
|
-
* Get the response for a successful password reset.
|
194
|
-
|
195
|
-
*
|
196
|
-
|
197
|
-
* @param \Illuminate\Http\Request $request
|
198
|
-
|
199
|
-
* @param string $response
|
200
|
-
|
201
|
-
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
|
202
|
-
|
203
|
-
*/
|
204
|
-
|
205
|
-
protected function sendResetResponse(Request $request, $response)
|
206
|
-
|
207
|
-
{
|
208
|
-
|
209
|
-
if ($request->wantsJson()) {
|
210
|
-
|
211
|
-
return new JsonResponse(['message' => trans($response)], 200);
|
212
|
-
|
213
|
-
}
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
return redirect($this->redirectPath()) // ここ
|
218
|
-
|
219
|
-
->with('status', trans($response));
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
|
163
|
+
(省略)
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
`$this->redirectPath()` を確認する
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
```php
|
232
|
-
|
233
|
-
<?php
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
namespace Illuminate\Foundation\Auth;
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
trait RedirectsUsers
|
242
|
-
|
243
|
-
{
|
244
|
-
|
245
|
-
/**
|
246
|
-
|
247
|
-
* Get the post register / login redirect path.
|
248
|
-
|
249
|
-
*
|
250
|
-
|
251
|
-
* @return string
|
252
|
-
|
253
|
-
*/
|
254
|
-
|
255
|
-
public function redirectPath()
|
256
|
-
|
257
|
-
{
|
258
|
-
|
259
|
-
if (method_exists($this, 'redirectTo')) {
|
260
|
-
|
261
|
-
return $this->redirectTo();
|
262
|
-
|
263
|
-
}
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
|
268
|
-
|
269
|
-
}
|
270
164
|
|
271
165
|
}
|
272
166
|
|
@@ -274,80 +168,16 @@
|
|
274
168
|
|
275
169
|
|
276
170
|
|
277
|
-
|
171
|
+
この部分にレスポンスを返している部分が見つかる
|
278
172
|
|
279
173
|
|
280
174
|
|
281
175
|
```php
|
282
176
|
|
283
|
-
|
177
|
+
return $response == Password::RESET_LINK_SENT
|
284
178
|
|
179
|
+
? $this->sendResetLinkResponse($request, $response)
|
285
180
|
|
286
|
-
|
287
|
-
namespace App\Http\Controllers\Auth;
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
use App\Http\Controllers\Controller;
|
292
|
-
|
293
|
-
use App\Providers\RouteServiceProvider;
|
294
|
-
|
295
|
-
use Illuminate\Foundation\Auth\ResetsPasswords;
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
class ResetPasswordController extends Controller
|
300
|
-
|
301
|
-
{
|
302
|
-
|
303
|
-
/*
|
304
|
-
|
305
|
-
|--------------------------------------------------------------------------
|
306
|
-
|
307
|
-
| Password Reset Controller
|
308
|
-
|
309
|
-
|--------------------------------------------------------------------------
|
310
|
-
|
311
|
-
|
|
312
|
-
|
313
|
-
|
181
|
+
: $this->sendResetLinkFailedResponse($request, $response);
|
314
|
-
|
315
|
-
| and uses a simple trait to include this behavior. You're free to
|
316
|
-
|
317
|
-
| explore this trait and override any methods you wish to tweak.
|
318
|
-
|
319
|
-
|
|
320
|
-
|
321
|
-
*/
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
use ResetsPasswords;
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
/**
|
330
|
-
|
331
|
-
* Where to redirect users after resetting their password.
|
332
|
-
|
333
|
-
*
|
334
|
-
|
335
|
-
* @var string
|
336
|
-
|
337
|
-
*/
|
338
|
-
|
339
|
-
protected $redirectTo = RouteServiceProvider::HOME;
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
public function redirectTo()
|
344
|
-
|
345
|
-
{
|
346
|
-
|
347
|
-
return ''; // ここに実装すれば良い
|
348
|
-
|
349
|
-
}
|
350
|
-
|
351
|
-
}
|
352
182
|
|
353
183
|
```
|
3
修正
test
CHANGED
@@ -1,11 +1,3 @@
|
|
1
|
-
[https://readouble.com/laravel/7.x/ja/verification.html](https://readouble.com/laravel/7.x/ja/verification.html)
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
![イメージ説明](85ee6d48b6e24bb336c829ff0a418b5e.png)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
1
|
`php artisan route:list | grep ResetPasswordController`
|
10
2
|
|
11
3
|
|
2
追記
test
CHANGED
@@ -187,3 +187,175 @@
|
|
187
187
|
略
|
188
188
|
|
189
189
|
```
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
`sendResetResponse()` の実装を見る
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
```php
|
198
|
+
|
199
|
+
/**
|
200
|
+
|
201
|
+
* Get the response for a successful password reset.
|
202
|
+
|
203
|
+
*
|
204
|
+
|
205
|
+
* @param \Illuminate\Http\Request $request
|
206
|
+
|
207
|
+
* @param string $response
|
208
|
+
|
209
|
+
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
|
210
|
+
|
211
|
+
*/
|
212
|
+
|
213
|
+
protected function sendResetResponse(Request $request, $response)
|
214
|
+
|
215
|
+
{
|
216
|
+
|
217
|
+
if ($request->wantsJson()) {
|
218
|
+
|
219
|
+
return new JsonResponse(['message' => trans($response)], 200);
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
return redirect($this->redirectPath()) // ここ
|
226
|
+
|
227
|
+
->with('status', trans($response));
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
```
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
`$this->redirectPath()` を確認する
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
```php
|
240
|
+
|
241
|
+
<?php
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
namespace Illuminate\Foundation\Auth;
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
trait RedirectsUsers
|
250
|
+
|
251
|
+
{
|
252
|
+
|
253
|
+
/**
|
254
|
+
|
255
|
+
* Get the post register / login redirect path.
|
256
|
+
|
257
|
+
*
|
258
|
+
|
259
|
+
* @return string
|
260
|
+
|
261
|
+
*/
|
262
|
+
|
263
|
+
public function redirectPath()
|
264
|
+
|
265
|
+
{
|
266
|
+
|
267
|
+
if (method_exists($this, 'redirectTo')) {
|
268
|
+
|
269
|
+
return $this->redirectTo();
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
|
276
|
+
|
277
|
+
}
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
```
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
`redirectTo` というメソッドがあれば、その設定を使うコードになっているので、
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
```php
|
290
|
+
|
291
|
+
<?php
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
namespace App\Http\Controllers\Auth;
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
use App\Http\Controllers\Controller;
|
300
|
+
|
301
|
+
use App\Providers\RouteServiceProvider;
|
302
|
+
|
303
|
+
use Illuminate\Foundation\Auth\ResetsPasswords;
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
class ResetPasswordController extends Controller
|
308
|
+
|
309
|
+
{
|
310
|
+
|
311
|
+
/*
|
312
|
+
|
313
|
+
|--------------------------------------------------------------------------
|
314
|
+
|
315
|
+
| Password Reset Controller
|
316
|
+
|
317
|
+
|--------------------------------------------------------------------------
|
318
|
+
|
319
|
+
|
|
320
|
+
|
321
|
+
| This controller is responsible for handling password reset requests
|
322
|
+
|
323
|
+
| and uses a simple trait to include this behavior. You're free to
|
324
|
+
|
325
|
+
| explore this trait and override any methods you wish to tweak.
|
326
|
+
|
327
|
+
|
|
328
|
+
|
329
|
+
*/
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
use ResetsPasswords;
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
/**
|
338
|
+
|
339
|
+
* Where to redirect users after resetting their password.
|
340
|
+
|
341
|
+
*
|
342
|
+
|
343
|
+
* @var string
|
344
|
+
|
345
|
+
*/
|
346
|
+
|
347
|
+
protected $redirectTo = RouteServiceProvider::HOME;
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
public function redirectTo()
|
352
|
+
|
353
|
+
{
|
354
|
+
|
355
|
+
return ''; // ここに実装すれば良い
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
}
|
360
|
+
|
361
|
+
```
|
1
追記
test
CHANGED
@@ -3,3 +3,187 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
![イメージ説明](85ee6d48b6e24bb336c829ff0a418b5e.png)
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
`php artisan route:list | grep ResetPasswordController`
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
```
|
14
|
+
|
15
|
+
% php artisan route:list | grep ResetPasswordController
|
16
|
+
|
17
|
+
| | POST | password/reset | password.update | App\Http\Controllers\Auth\ResetPasswordController@reset | web |
|
18
|
+
|
19
|
+
| | GET|HEAD | password/reset/{token} | password.reset | App\Http\Controllers\Auth\ResetPasswordController@showResetForm | web |
|
20
|
+
|
21
|
+
```
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
`ResetPasswordController` をみる
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
```php
|
30
|
+
|
31
|
+
<?php
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
namespace App\Http\Controllers\Auth;
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
use App\Http\Controllers\Controller;
|
40
|
+
|
41
|
+
use App\Providers\RouteServiceProvider;
|
42
|
+
|
43
|
+
use Illuminate\Foundation\Auth\ResetsPasswords;
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
class ResetPasswordController extends Controller
|
48
|
+
|
49
|
+
{
|
50
|
+
|
51
|
+
/*
|
52
|
+
|
53
|
+
|--------------------------------------------------------------------------
|
54
|
+
|
55
|
+
| Password Reset Controller
|
56
|
+
|
57
|
+
|--------------------------------------------------------------------------
|
58
|
+
|
59
|
+
|
|
60
|
+
|
61
|
+
| This controller is responsible for handling password reset requests
|
62
|
+
|
63
|
+
| and uses a simple trait to include this behavior. You're free to
|
64
|
+
|
65
|
+
| explore this trait and override any methods you wish to tweak.
|
66
|
+
|
67
|
+
|
|
68
|
+
|
69
|
+
*/
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
use ResetsPasswords;
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
/**
|
78
|
+
|
79
|
+
* Where to redirect users after resetting their password.
|
80
|
+
|
81
|
+
*
|
82
|
+
|
83
|
+
* @var string
|
84
|
+
|
85
|
+
*/
|
86
|
+
|
87
|
+
protected $redirectTo = RouteServiceProvider::HOME;
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
```
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
trait を使っているのでそのファイルを見る
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
```php
|
100
|
+
|
101
|
+
<?php
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
namespace Illuminate\Foundation\Auth;
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
use Illuminate\Auth\Events\PasswordReset;
|
110
|
+
|
111
|
+
use Illuminate\Http\JsonResponse;
|
112
|
+
|
113
|
+
use Illuminate\Http\Request;
|
114
|
+
|
115
|
+
use Illuminate\Support\Facades\Auth;
|
116
|
+
|
117
|
+
use Illuminate\Support\Facades\Hash;
|
118
|
+
|
119
|
+
use Illuminate\Support\Facades\Password;
|
120
|
+
|
121
|
+
use Illuminate\Support\Str;
|
122
|
+
|
123
|
+
use Illuminate\Validation\ValidationException;
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
trait ResetsPasswords
|
128
|
+
|
129
|
+
{
|
130
|
+
|
131
|
+
use RedirectsUsers;
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
/**
|
136
|
+
|
137
|
+
* Reset the given user's password.
|
138
|
+
|
139
|
+
*
|
140
|
+
|
141
|
+
* @param \Illuminate\Http\Request $request
|
142
|
+
|
143
|
+
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
|
144
|
+
|
145
|
+
*/
|
146
|
+
|
147
|
+
public function reset(Request $request)
|
148
|
+
|
149
|
+
{
|
150
|
+
|
151
|
+
$request->validate($this->rules(), $this->validationErrorMessages());
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
// Here we will attempt to reset the user's password. If it is successful we
|
156
|
+
|
157
|
+
// will update the password on an actual user model and persist it to the
|
158
|
+
|
159
|
+
// database. Otherwise we will parse the error and return the response.
|
160
|
+
|
161
|
+
$response = $this->broker()->reset(
|
162
|
+
|
163
|
+
$this->credentials($request), function ($user, $password) {
|
164
|
+
|
165
|
+
$this->resetPassword($user, $password);
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
);
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
// If the password was successfully reset, we will redirect the user back to
|
174
|
+
|
175
|
+
// the application's home authenticated view. If there is an error we can
|
176
|
+
|
177
|
+
// redirect them back to where they came from with their error message.
|
178
|
+
|
179
|
+
return $response == Password::PASSWORD_RESET
|
180
|
+
|
181
|
+
? $this->sendResetResponse($request, $response) // 多分ここだと推測できる
|
182
|
+
|
183
|
+
: $this->sendResetFailedResponse($request, $response);
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
略
|
188
|
+
|
189
|
+
```
|