我正在尝试为自定义用户(job_seeker)应用电子邮件验证,到目前为止,我所做的如下: 为“ job_seeker”后卫创建了验证路线。 用新视图覆盖Verification控制器中的show方法。 在Job_Seeker模型中实现了新的通知。 创建,注册并应用了一个名为“ job_seeker.verified”的新中间件。
我已经尝试过该解决方案 Apply Laravel 5.7 MustVerifyEmail on Multiple Authentication System
此过程完成后,我发现它正在向电子邮件发送通知并显示验证页面,但是当我单击邮件中的“验证电子邮件地址”按钮时,它不会使用时间戳更新数据库,并且不会花费时间我到重定向页面。而是显示“页面403
Route::get('/email/verify','job_seeker\Job_Seeker_Verification@show')->name('job_seeker/verify/notice');
Route::get('/email/verify/{id}','job_seeker\Job_Seeker_Verification@verify')->name('job_seeker.verification.verify');
求职者的注册控制器
$job_seeker=Job_Seeker::create([
'username' => $request['username'],
'email' => $request['email'],
'city'=> $request['city'],
'categories' => $request['categories'],
'password' => Hash::make($request['password']),
]);
$job_seeker->notify(new Job_seeker_Email_Verification($job_seeker));
if (Auth::guard('job_seeker')->attempt(['email' => $request->email,
'password' => $request->password], $request->remember)) {
// if successful, then redirect to their intended location
return redirect()->intended(route('job_seeker/jobs'));
}
job_seeker的验证控制器
public function __construct()
{
$this->middleware('auth:job_seeker');
$this->middleware('signed')->only('verify');
$this->middleware('throttle:6,1')->only('verify', 'resend');
}
public function show(Request $request)
{
return $request->user()->hasVerifiedEmail()
? redirect($this->redirectPath())
: view('job_seeker.verify');
}
目标页面
public function __construct()
{
$this->middleware('auth:job_seeker');
$this->middleware('job_seeker_verified');
}
public function show_jobs(){
return view('job_seeker.job_listing');
}
来自
的电子邮件如果您在单击“验证电子邮件地址”按钮时遇到麻烦,请将下面的URL复制并粘贴到网络浏览器中:http://127.0.0.1:8000/job_seeker/email/verify/6?expires=1571589961&signature=0ac1b0ed2f8463094006ee3af2537771889c8fd598ad119c7be77c2b44e857d0
EnsureEmailIsVerified中间件
$guards = array_keys(config('auth.guards'));
foreach($guards as $guard) {
if ($guard == 'job_seeker') {
if (Auth::guard($guard)->check()) {
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/verify/notice');
}
}
}
elseif ($guard == 'web') {
if (Auth::guard($guard)->check()) {
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('verification.notice');
}
}
}
}