laravel - 登录后的中间件
问题描述
我希望中间件在登录后立即运行以进行两步验证。
我尝试在 Kernel.php 文件的受保护 $ routeMiddleware 内添加以下行 'login' => \ App \ Http \ Middleware \ TwoFactorVerify :: 类。
解决方案
您希望中间件在Authenticate
检查每个身份验证请求的中间件之后运行。在 Kernel.php 中注册你的中间件,然后在你想要的路由上这样做:
Route::get('example', 'ExampleController@example')->middleware(['auth', 'login']);
如果您希望您的中间件应用于一组路由,请这样做:
Route::middleware(['auth', 'login'])
->group(function () {
Route::get('example', 'ExampleController@example');
Route::get('example2', 'ExampleController@example2');
});
您可以two_factor_verified => true
在用户验证代码后进行设置。然后,在TwoFactorVerify
中间件中,您可以像这样检查:
if($request-session()->get('two_factor_verified'))
{
return $next($request);
}
return new TwoFactorNotVerifiedException();
推荐阅读
- regex - Lucene Regex 用于字母数字匹配,但不是所有数字
- javascript - 是否可以将 keyup 功能替换为按钮单击功能?
- apache-spark - 如何获取 Azure Databricks 笔记本运行详细信息
- javascript - 如何在 JAVASCRIPT 的对象中添加键值对?
- javascript - 如何正确地将德语日期字符串转换为日期?
- json - 从多级 JSON 中获取数据
- swift - 在 DatePicker-swift 中限制小时和分钟?
- html - 如何让我的 h2 元素出现在我的标题元素下?
- javascript - 使用 JavaScript 在默认操作系统浏览器中打开 url
- jasper-reports - 有没有办法在jasper中调用多个数据?