为什么不触发UserNotVerifiedException错误?

时间:2018-09-20 12:22:16

标签: laravel-5 verification

在我的laravel 5.7.3应用程序中,我使用https://github.com/jrean/laravel-user-verification扩展,并使用 中间件我未登录时生成UserNotVerifiedException错误 但是我想以注销的方式退出并重定向到/ login页面,并阅读https://laravel.com/docs/master/errors#the-exception-handler文档 我做的文件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: {▶}
}

哪种方法有效?

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以尝试将原始名称空间放入:

import yaml

with open("example.yml", "r") as f:
    test_data = yaml.load(f)

def test_valid_number():
    response = requests.get(test_data['url']).json()
    assert response == test_data['expected']