回答編集履歴

3

修正

2016/11/30 02:05

投稿

qwe001
qwe001

スコア133

test CHANGED
@@ -264,6 +264,8 @@
264
264
 
265
265
  return (new MailMessage)
266
266
 
267
+ ->subject('パスワードリセット') // メールの件名
268
+
267
269
  ->view('admin.emails.password') // resources/views/admin/emails/password.blade.phpを表示します
268
270
 
269
271
  ->action('Reset Password', url('admin/password/reset', $this->token)); // $actionUrlという変数にトークン情報を含めたパスワードリセットのURLを格納します。これは上記のviewで参照可能です。
@@ -299,3 +301,125 @@
299
301
  <a href="{{ $actionUrl }}">{{ $actionUrl }}</a>
300
302
 
301
303
  ```
304
+
305
+
306
+
307
+ ### 5. リセット後のリダイレクト先の設定
308
+
309
+
310
+
311
+ リセット完了後のリダイレクト先が通常は /home に飛ぶことになっていますが、これを /admin に飛ぶようにします。
312
+
313
+
314
+
315
+ app/Http/Controller/Admin/Auth/ResetPasswordController.php
316
+
317
+
318
+
319
+ ```
320
+
321
+ <?php
322
+
323
+
324
+
325
+ namespace App\Http\Controllers\Admin\Auth;
326
+
327
+
328
+
329
+ use App\Http\Controllers\Controller;
330
+
331
+ use Illuminate\Foundation\Auth\ResetsPasswords;
332
+
333
+
334
+
335
+ use Illuminate\Http\Request;
336
+
337
+
338
+
339
+ class ResetPasswordController extends Controller
340
+
341
+ {
342
+
343
+ /*
344
+
345
+ |--------------------------------------------------------------------------
346
+
347
+ | Password Reset Controller
348
+
349
+ |--------------------------------------------------------------------------
350
+
351
+ |
352
+
353
+ | This controller is responsible for handling password reset requests
354
+
355
+ | and uses a simple trait to include this behavior. You're free to
356
+
357
+ | explore this trait and override any methods you wish to tweak.
358
+
359
+ |
360
+
361
+ */
362
+
363
+
364
+
365
+ use ResetsPasswords;
366
+
367
+
368
+
369
+ protected $redirectTo = '/admin'; // 追加
370
+
371
+
372
+
373
+ /**
374
+
375
+ * Display the password reset view for the given token.
376
+
377
+ *
378
+
379
+ * If no token is present, display the link request form.
380
+
381
+ *
382
+
383
+ * @param \Illuminate\Http\Request $request
384
+
385
+ * @param string|null $token
386
+
387
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
388
+
389
+ */
390
+
391
+ public function showResetForm(Request $request, $token = null)
392
+
393
+ {
394
+
395
+ return view('admin.passwords.reset')->with(
396
+
397
+ ['token' => $token, 'email' => $request->email]
398
+
399
+ );
400
+
401
+ }
402
+
403
+
404
+
405
+ /**
406
+
407
+ * Create a new controller instance.
408
+
409
+ *
410
+
411
+ * @return void
412
+
413
+ */
414
+
415
+ public function __construct()
416
+
417
+ {
418
+
419
+ $this->middleware('guest');
420
+
421
+ }
422
+
423
+ }
424
+
425
+ ```

2

修正

2016/11/30 02:05

投稿

qwe001
qwe001

スコア133

test CHANGED
@@ -1,3 +1,15 @@
1
+ ### 2016/11/30 修正
2
+
3
+
4
+
5
+ 前回提示した内容で確かにviewは表示されるのですが、トークン情報を持ってこれないので、
6
+
7
+ TokenMismatchでパスワードのリセットができないという致命的な欠陥を発見しました。
8
+
9
+ そこで、トークン情報を引き継ぎ、任意のViewをメール本文に表示する方法がわかったので内容を一部変更します。
10
+
11
+
12
+
1
13
  fagai様
2
14
 
3
15
  返信ありがとうございます。回答が遅くなり申し訳ありません。
@@ -8,11 +20,19 @@
8
20
 
9
21
 
10
22
 
11
- こちらを参考にしました。というかまんまです。
23
+ (修正前)こちらを参考にしました。というかまんまです。
12
-
13
-
14
-
24
+
25
+
26
+
15
- http://stackoverflow.com/questions/39327954/laravel-5-3-redefine-reset-email-blade-template
27
+ [http://stackoverflow.com/questions/39327954/laravel-5-3-redefine-reset-email-blade-template](http://stackoverflow.com/questions/39327954/laravel-5-3-redefine-reset-email-blade-template)
28
+
29
+
30
+
31
+ (修正後)こちらが大変参考になりました。
32
+
33
+
34
+
35
+ [http://takayukii.me/post/20160914887](http://takayukii.me/post/20160914887)
16
36
 
17
37
 
18
38
 
@@ -20,6 +40,10 @@
20
40
 
21
41
 
22
42
 
43
+ 修正前のものから変更はありません
44
+
45
+
46
+
23
47
  ```
24
48
 
25
49
  php artisan make:notification CustomPasswordReset
@@ -32,6 +56,10 @@
32
56
 
33
57
 
34
58
 
59
+ 修正前のものから変更はありません
60
+
61
+
62
+
35
63
  app/User.php
36
64
 
37
65
 
@@ -120,19 +148,11 @@
120
148
 
121
149
 
122
150
 
123
- ### 3. テンプレートファイルを生成
124
-
125
-
126
-
127
- ```
128
-
129
- php artisan vendor:publish --tag=laravel-notifications
130
-
131
- ```
132
-
133
-
134
-
135
- ### 4. リセットメールを再定義
151
+ ### 3. リセットメールを再定義
152
+
153
+
154
+
155
+ 修正前のものから内容を全て書き換えています。
136
156
 
137
157
 
138
158
 
@@ -160,29 +180,45 @@
160
180
 
161
181
 
162
182
 
183
+ use Illuminate\Auth\Notifications\ResetPassword; // 追加
184
+
185
+
186
+
163
- class CustomPasswordReset extends Notification
187
+ class CustomPasswordReset extends ResetPassword // extendsをNotificationからResetPasswordに変更
164
188
 
165
189
  {
166
190
 
167
- use Queueable;
168
-
169
-
170
-
171
- /**
191
+ /**
172
-
192
+
173
- * Create a new notification instance.
193
+ * The password reset token.
174
-
194
+
175
- *
195
+ *
196
+
197
+ * @var string
198
+
199
+ */
200
+
201
+ public $token;
202
+
203
+
204
+
205
+ /**
206
+
207
+ * Create a notification instance.
208
+
209
+ *
210
+
211
+ * @param string $token
176
212
 
177
213
  * @return void
178
214
 
179
215
  */
180
216
 
181
- public function __construct()
217
+ public function __construct($token)
182
218
 
183
219
  {
184
220
 
185
- //
221
+ $this->token = $token;
186
222
 
187
223
  }
188
224
 
@@ -190,13 +226,13 @@
190
226
 
191
227
  /**
192
228
 
193
- * Get the notification's delivery channels.
229
+ * Get the notification's channels.
194
230
 
195
231
  *
196
232
 
197
233
  * @param mixed $notifiable
198
234
 
199
- * @return array
235
+ * @return array|string
200
236
 
201
237
  */
202
238
 
@@ -212,7 +248,7 @@
212
248
 
213
249
  /**
214
250
 
215
- * Get the mail representation of the notification.
251
+ * Build the mail representation of the notification.
216
252
 
217
253
  *
218
254
 
@@ -226,36 +262,40 @@
226
262
 
227
263
  {
228
264
 
265
+ return (new MailMessage)
266
+
229
- return (new MailMessage)->view('admin.emails.password'); // ここ変更
267
+ ->view('admin.emails.password') // resources/views/admin/emails/password.blade.php表示します
268
+
269
+ ->action('Reset Password', url('admin/password/reset', $this->token)); // $actionUrlという変数にトークン情報を含めたパスワードリセットのURLを格納します。これは上記のviewで参照可能です。
230
270
 
231
271
  }
232
272
 
233
-
234
-
235
- /**
236
-
237
- * Get the array representation of the notification.
238
-
239
- *
240
-
241
- * @param mixed $notifiable
242
-
243
- * @return array
244
-
245
- */
246
-
247
- public function toArray($notifiable)
248
-
249
- {
250
-
251
- return [
252
-
253
- //
254
-
255
- ];
256
-
257
- }
258
-
259
273
  }
260
274
 
261
275
  ```
276
+
277
+
278
+
279
+ ### 4. リセットメールのViewを作成
280
+
281
+
282
+
283
+ ```
284
+
285
+ touch resources/views/admin/emails/password.blade.php
286
+
287
+ ```
288
+
289
+
290
+
291
+ ```
292
+
293
+ パスワードを再設定します的な文章を書きます。Doctype宣言やhtmlタグやbodyタグは不要です。
294
+
295
+ $actionUrlは、次のような内容を表示します。http://example.com/admin/password/reset/32c22536d66d7a994c9430a02a61e4498e86949a08ff39116882570d5385f91c
296
+
297
+ <br />
298
+
299
+ <a href="{{ $actionUrl }}">{{ $actionUrl }}</a>
300
+
301
+ ```

1

修正

2016/11/30 01:50

投稿

qwe001
qwe001

スコア133

test CHANGED
@@ -32,7 +32,11 @@
32
32
 
33
33
 
34
34
 
35
- ```php:app/User.php
35
+ app/User.php
36
+
37
+
38
+
39
+ ```php
36
40
 
37
41
 
38
42
 
@@ -132,7 +136,11 @@
132
136
 
133
137
 
134
138
 
135
- ```php:app/Notifications/CustomPasswordReset.php
139
+ app/Notifications/CustomPasswordReset.php
140
+
141
+
142
+
143
+ ```php
136
144
 
137
145
  <?php
138
146