laravel 5.7多身份验证电子邮件验证

时间:2019-09-22 12:29:03

标签: laravel laravel-5.7

我是Laravel的新手,我正在尝试为job_seeker设置电子邮件验证,但是在我注册新的job_seeker_verified之后,我重定向到个人资料页面,该页面必须受{{1 }}中间件 在正常情况下,我必须重定向到job_seeker/verify,它使用名为job_seeker_verification.notice的路由和控制器verification_controller以及使用带有验证消息显示视图的函数,但我得到了

  

禁止页面403

namespace App\Http\Controllers\job_seeker;

use App\Job_seeker;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class job_seeker_profile_controller extends Controller
{
    public function __construct()
    {
        $this->middleware(['job_seeker_auth', 'job_seeker_verified']);
    }

    public function show_profile(Job_seeker $job_seeker)
    {
        return view('profile.job_seeker_profile');
    }
}
namespace App\Http\Middleware;

use Illuminate\Support\Facades\Redirect;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Support\Facades\Auth;
use Closure;

class Ensure_Job_Seeker_Is_Verified
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        $guard == 'job_seeker';
        if (
            !Auth::guard($guard)->user() || (Auth::guard($guard)->user() instanceof MustVerifyEmail &&
                !Auth::guard($guard)->user()->hasVerifiedEmail())
        ) {
            return $request->expectsJson()
                ? abort(403, 'Your email address is not verified.')
                : Redirect::route('job_seeker_verification.notice');
        }
        return $next($request);
    }
}
namespace App\Http\Controllers\job_seeker;

use Illuminate\Http\Request;
use App\Job_seeker;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\VerifiesEmails;

class Verification_Controller extends Controller
{
    use VerifiesEmails;
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    protected $redirectTo = 'job_seeker.profile';
    public function __construct()
    {
        $this->middleware('job_seeker_auth');
        $this->middleware('signed');
        $this->middleware('throttle:6,1')->only('resend');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show(Request $request)
    {
        return $request->user()->hasVerifiedEmail()
            ? redirect($this->redirectPath())
            : view('profile.job_seeker_verify');
    }
    public function verify(Request $request)
    {
        if ($request->route('id') != $request->user()->getKey()) {
            throw new AuthorizationException;
        }

        if ($request->user()->hasVerifiedEmail()) {
            return redirect($this->redirectPath());
        }

        if ($request->user()->markEmailAsVerified()) {
            event(new Verified($request->user()));
        }

        return redirect($this->redirectPath())->with('job_seeker_verified', true);
    }
}
Route::get('job_seeker_email.resend', [
    'as'=>'job_seeker_email.verification.resend', 'uses'=>'job_seeker\Job_Seeker_Verication_email@resend'
    ]);
Route::get('job_seeker/verify', [
    'as'=>'job_seeker_verification.notice', 'uses'=>'job_seeker\Verification_Controller@show'
    ]);
Route::get('job_seeker/verify/{id}', [
    'as'=>'job_seeker_verification.verify','uses'=>'job_seeker\Verification_Controller@verify'
    ]);

1 个答案:

答案 0 :(得分:0)

删除

$this->middleware('job_seeker_auth');

来自verification_controller构造函数,因为它在到达showverify方法之前返回403
未经验证的用户无法验证自己的身份