在多重身份验证系统上应用Laravel 5.7 MustVerifyEmail [英] Apply Laravel 5.7 MustVerifyEmail on Multiple Authentication System
问题描述
我正在尝试在多个身份验证系统上应用Laravel-5.7 MustVerifyEmail.到目前为止,我所做的如下:
I'm trying to apply Laravel-5.7 MustVerifyEmail on multiple authentication system. So far what I've done is as follows:
- 为审计师"后卫创建了验证路径.
- 用新的视图覆盖Verification控制器中的show方法.
- 在审核员模型中实施了新通知.
- 创建,注册并应用了一个名为"auditor.verified"的新中间件.
此过程完成后,我发现它正在向电子邮件发送通知并显示验证页面,但是当我单击邮件中的验证电子邮件地址"按钮时,它将使用时间戳更新数据库,但不会占用我的时间到重定向页面.相反,我在浏览器中收到页面无法正常工作"的消息.
After this procedure, I find that it's sending a notification to email and shows the verify page but when I click on the 'Verify Email Address' button in the mail it update the database with the timestamp but it don't take me to the redirect page. Instead, I get "The page isn't working" message in the browser.
我应该错过一些东西.
这是GitHub上的项目文件
Here is the project file on GitHub
预先感谢您的帮助.
推荐答案
最后,经过四天的研究,我终于能够解决问题.
Finally, after four days of research I was able to solve the issue.
我如下更改了"EnsureEmailIsVerified"中间件:
I altered the "EnsureEmailIsVerified" middleware as follows:
<?php
namespace Illuminate\Auth\Middleware;
use Closure;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Support\Facades\Auth;
class EnsureEmailIsVerified
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle($request, Closure $next, $guard = null)
{
$guards = array_keys(config('auth.guards'));
foreach($guards as $guard) {
if ($guard == 'admin') {
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('admin.verification.notice');
}
}
}
elseif ($guard == 'auditor') {
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('auditor.verification.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');
}
}
}
}
return $next($request);
}
}
这解决了我的问题.
这篇关于在多重身份验证系统上应用Laravel 5.7 MustVerifyEmail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!