首页 > 解决方案 > Laravel问题从电子邮件验证传递错误消息

问题描述

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

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

标签: phplaravellaravel-8

解决方案


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

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

推荐阅读