【问题标题】:Why UserNotVerifiedException error is not trigered?为什么未触发用户未验证异常错误?
【发布时间】:2019-02-24 18:20:38
【问题描述】:

在我的 laravel 5.7.3 应用程序中,我使用 https://github.com/jrean/laravel-user-verification 扩展并使用 未验证登录时生成 UserNotVerifiedException 错误的中间件 但除了我想注销并重定向到 /login 页面并阅读https://laravel.com/docs/master/errors#the-exception-handler doc in 文件 app/Exceptions/Handler.php 我做的:

<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Auth;
use App\Exceptions\UserNotVerifiedException;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Foundation\Auth\RegistersUsers;

use Jrean\UserVerification\Traits\VerifiesUsers;  // Do I need to add these declarations here ?
use Jrean\UserVerification\Facades\UserVerification;

class Handler extends ExceptionHandler
{
    use RegistersUsers;
    use VerifiesUsers;
    protected $dontReport = [
        //
    ];

    protected $dontFlash = [
        'password',
        'password_confirmation',
    ];

    public function report(Exception $exception)
    {
        parent::report($exception);
    }

    public function render($request, Exception $exception)
    {
        dump($exception);
        if ($exception instanceof UserNotVerifiedException) {
            dump("Make Logout");
            Auth::logout();
            return redirect('/admin/dashboard/index');

        }
        return parent::render($request, $exception);
    }
}

在转储文件中,我看到第一条消息,但没有看到第二条消息(以及为什么没有重定向):

UserNotVerifiedException {#509 ▼
  #message: "This user is not verified."
  #code: 0
  #file: "/mnt/_work_sdb8/wwwroot/lar/Votes/vendor/jrean/laravel-user-verification/src/Middleware/IsVerified.php"
  #line: 26
  trace: {▶}
}

哪种方式有效?

谢谢!

【问题讨论】:

  • 你在使用包jrean/laravel-user-verification吗?
  • 是的,我在主题描述中提到过。

标签: laravel-5 verification


【解决方案1】:

你可以尝试把原来的命名空间像:

if ($exception instanceof \Jrean\UserVerification\Exceptions\UserNotVerifiedException) {
    dump("Make Logout");
    Auth::logout();
    return redirect('/admin/dashboard/index');
}

【讨论】:

    猜你喜欢
    • 2012-11-18
    • 1970-01-01
    • 2013-12-15
    • 2011-05-27
    • 1970-01-01
    • 1970-01-01
    • 2013-11-23
    • 2011-06-23
    • 2014-05-11
    相关资源
    最近更新 更多