按照启用新的内置电子邮件验证的安装后,一切正常(注册后发送电子邮件并单击激活启用帐户)。
但是,我遇到了用户必须登录才能进行验证过程的情况。意思是,如果用户在使用验证链接之前没有登录,他将被重定向到登录页面,然后显示 /resources/view/auth/verify.blade.php
页。
我正在与社区联系,看看这是故意的,是错误还是我做错了什么?有人在同样的情况下运行吗?
我正在建立的站点可以公开访问大多数页面,但仅限于某些页面(现在是用户门户)。我设置了routes/web.php
如下:
// Authentication
Auth::routes(['verify' => true]);
Route::group(['middleware' => ['auth', 'verified'], 'as' => 'portal.', 'prefix' => '/portal'], function () {
Route::get('/', 'PortalController@index');
Route::get('/profile', 'PortalController@index')->name('profile');
Route::get('/orders', 'PortalController@index')->name('orders');
});
通过跟踪验证过程,我能够在
VerificationController
中发现该过程正在强制登录。构造函数通过如下所示的中间件。public function __construct()
{
$this->middleware('auth');
$this->middleware('signed')->only('verify');
$this->middleware('throttle:6,1')->only('verify', 'resend');
}
通过注释第一行或添加
->except('verify')
,登录页面未显示,但在 Traits VerifiesEmails
处抛出错误方法验证如下,因为用户显然没有登录($request->user()
为空)。public function verify(Request $request)
{
if ($request->route('id') == $request->user()->getKey() &&
$request->user()->markEmailAsVerified()) {
event(new Verified($request->user()));
}
return redirect($this->redirectPath())->with('verified', true);
}
我的问题是,有没有办法让它在没有事先登录的情况下工作,或者这就是 5.7 中验证过程的实现方式? ……或者我做错了什么?
最佳答案
is there a way to get it to work without being loged-in beforehand, or is this the way the Verification process is implemented in 5.7? ... or what am I doing wrong?
这是在 Laravel 5.7 中实现验证过程的方式。 Laravel 使用签名 URL 进行验证。 URL 是用
id
生成的参数(id 作为用户 ID),当用户点击验证链接时,会进行 3 项检查:signed
中间件) 您始终可以通过覆盖 VerificationController 中的 verify 方法来删除第三个检查,如下所示:
public function verify(Request $request)
{
$userId = $request->route('id');
$user = App\User::findOrFail($userId);
if ($user->markEmailAsVerified()) {
event(new Verified($user));
}
return redirect($this->redirectPath())->with('verified', true);
}
关于php - Laravel 电子邮件验证 - 强制登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52949374/