[英]How to logout user through specified time in laravel
How can I logout a user after 48 hours.如何在 48 小时后注销用户。
public function generatePass(Request $request)
{
$myRandomString = Str::random(8);
DB::table('web_passes')->insert([
'pass' => $myRandomString,
'user_id' => $request->user_id,
'expiry_time' => Carbon::now()->addDays(2)
]);
you can change the SESSION_LIFETIME=20
in .env您可以在.env中更改
SESSION_LIFETIME=20
the life time of session in this example is 20 minutes本例中 session 的使用寿命为 20 分钟
so in any request should be authorize give it所以在任何请求中都应该授权给它
if(auth()->check())
complete execute if(auth()->check())
完成执行
else
remove or refersh token to invalid and redirect to login page删除或将令牌引用为无效并重定向到登录页面
I just did that by simply applying a middleware condition我只是通过简单地应用中间件条件来做到这一点
public function handle(Request $request, Closure $next)
{
$webPass = $request->user()->webPass;
if($webPass->expiry_time < Carbon::now()){
$randomString = str::random(8);
$webPass->pass = $randomString;
$webPass->expiry_time = Carbon::now()->addSeconds(30);
$webPass->update();
Auth::logout();
return redirect('/otp')->with('expiry_time', 'Your session has expired');
}
return $next($request);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.