問題描述
Laravel問題從電子郵件驗證傳遞錯誤消息 (Laravel problem to pass error message from email verification)
想求助,因為不知道怎麼告訴用戶激活鏈接不正確。
我覆蓋了verify方法,現在激活成功後,用戶接收信息。但是當鏈接無效時得到 403 | 無效的簽名。
我的想法已經用完了,我想將消息的形式更改為登錄頁面上顯示的引導警報
protected $redirectTo = '/login';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this‑>middleware('signed')‑>only('verify');
$this‑>middleware('throttle:6,1')‑>only('verify', 'resend');
}
public function verify(Request $request)
{
$user = User::find($request‑>route('id'));
if (!hash_equals((string) $request‑>route('hash'), sha1($user‑>getEmailForVerification()))) {
throw new AuthorizationException;
}
if ($user‑>markEmailAsVerified())
event(new Verified($user));
return redirect($this‑>redirectPath())‑>with('verified', true);
}
我嘗試了try catch,但它沒用
有人知道如何實現嗎?我正在使用 Laravel 8
參考解法
方法 1:
you can just check if the signature is valid or not then redirect or add a payload.
if (!$request‑>hasValidSignature()) {
// do stuff here (return view, redirect etc)
}
方法 2:
Maybe you could try changing the throw new AuthorizationException;
inside the verify method to add your own logic.
(by Ridster32、Mua Rachmann、Professor)