【问题标题】:Laravel problem to pass error message from email verificationLaravel问题从电子邮件验证传递错误消息
【发布时间】:2021-05-21 20:25:21
【问题描述】:

我想寻求帮助,因为我不知道如何告诉用户激活链接不正确。

我覆盖了验证方法,现在,成功激活后,用户会收到信息。但是当链接无效时得到 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

【问题讨论】:

    标签: php laravel laravel-8


    【解决方案1】:

    您可以检查签名是否有效,然后重定向或添加有效负载。

    if (!$request->hasValidSignature()) {
           // do stuff here (return view, redirect etc)
       }
    

    【讨论】:

    • 我试过了还是不行,即使我用dd()还是得到403
    【解决方案2】:

    也许您可以尝试更改 verify 方法中的 throw new AuthorizationException; 以添加您自己的逻辑。

    【讨论】:

      猜你喜欢
      • 2017-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-04
      • 1970-01-01
      • 2021-03-26
      • 2010-09-07
      相关资源
      最近更新 更多