2016-11-01 59 views
2

移動面向auth控制器我Http/Controllers/Admin/Auth目錄,以及移動的觀點是面向auth到admin/auth並設置路由後的文件是這樣的:Laravel 5.3 - 復位修改密碼身份驗證路線

Route::group(['middleware' => 'web', 'prefix' => 'admin', 'namespace' => 'Admin'], function() { 
    Auth::routes(); 
}); 

當點擊該鏈接在重置密碼電子郵件,我得到一個錯誤:

NotFoundHttpException in RouteCollection.php line 161:

我已經修改showResetForm方法在控制器中,像這樣:

public function showResetForm(Request $request, $token = null) 
    { 
     return view('admin.auth.passwords.reset')->with(
      ['token' => $token, 'email' => $request->email] 
     ); 
    } 

這是上php artisan route:list列出的路線:

  POST  | admin/password/email    |     | App\Http\Controllers\Admin\Auth\[email protected] | web,web,guest | 
|  | POST  | admin/password/reset    |     | App\Http\Controllers\Admin\Auth\[email protected]    | web,web,guest | 
|  | GET|HEAD | admin/password/reset    |     | App\Http\Controllers\Admin\Auth\[email protected] | web,web,guest | 
|  | GET|HEAD | admin/password/reset/{token}  |     | App\Http\Controllers\Admin\Auth\[email protected]  | web,web,guest | 
|  | GET|HEAD | admin/register     |     | App\Http\Controllers\Admin\Auth\[email protected]  | web,web,guest | 
|  | POST  | admin/register     |     | App\Http\Controllers\Admin\Auth\[email protected]     | web,web,guest 

,用戶接收郵件的密碼重置仍然是指向沒有Admin前綴老路線的鏈接,我怎樣才能改變這種狀況?

回答

0

首先你必須覆蓋Illuminate\Auth\Notifications\ResetPasswordtoMail函數。將[URL_TO_RESETPWD]替換爲您的網址。

namespace App\Notifications; 

use Illuminate\Auth\Notifications\ResetPassword; 
use Illuminate\Notifications\Messages\MailMessage; 

class AppResetPassword extends ResetPassword { 

    // Overriding the function 
    public function toMail($notifiable) { 
     return (new MailMessage) 
      ->line('You are receiving this email because we received a password reset request for your account.') 
      ->action('Reset Password', [URL_TO_RESETPWD], $this->token)) 
      ->line('If you did not request a password reset, no further action is required.'); 
    } 
} 

Next在您的管理員用戶覆蓋模型CanResetPassword性狀sendPasswordResetNotification功能使用你上面的類。

public function sendPasswordResetNotification($token) { 
    $this->notify(new App\Notifications\AppResetPassword\ResetPasswordNotification($token)); 
} 

希望這會對你有幫助。

0

我遇到了這個問題,並希望使用我自己的純文本電子郵件。

添加到您的User型號:

public function sendPasswordResetNotification($token) 
{ 
    Mail::send(['text' => 'emails.password'], ['token' => $token], function ($message) { 
     $message->subject(config('app.name').' Password Reset Link'); 
     $message->to($this->email); 
    }); 
} 

創建views/emails/password.blade.php

You are receiving this email because we received a password reset request for your account. 

Click here to reset your password: {{ url('auth/password/reset/'.$token) }} 

If you did not request a password reset, no further action is required. 

這將會給他們發送明文密碼重置電子郵件,並會擺脫password.reset路徑未找到錯誤的。

+0

對於任何希望根據路由名稱生成url的用戶,可以使用:route('password.reset',['token'=> {your token}]) –