由于不活动,页面已过期。请刷新并在登录中重试

问题描述 投票:1回答:5

当我尝试登录时我的登录有问题说由于不活动而导致页面已过期。我正在使用中间件根据用户登录检查角色,似乎它无法正常工作。当试图登录页面时有过期的消息弹出窗口。

路线:

Route::get('/', function () {
    return view('login');
});

Route::get('/dashboard/{user_id}', ['as' => 'dashboard', function ($user_id) {
    return view('theme.index')->with(['id'=>$user_id]);
}]);
Route::post('login', 'AuthController@postSignIn')->name('login');

AuthController:

 public function postSignIn(Request $request)
    {

        if (Auth::attempt(['username' => $request['username'], 'password' => $request['password']])) {
            $user=DB::table('users')->where([['username', '=', $request['username']],['status','=','0']])->first();
            $user_id=$user->user_id;


            return redirect()->route('dashboard',$user_id)->with('message', 'State saved correctly!!!');
        } else {
            return redirect()->back();
        }
    }

中间件:

public function handle($request, Closure $next)
    {
        if ($request->user() === null) {
            //  return response("Insufficient permissions", 401);
            return response(view('error'),401);
        }
        $actions = $request->route()->getAction();
        $roles = isset($actions['roles']) ? $actions['roles'] : null;

        if ($request->user()->hasAnyRole($roles) || !$roles) {
            return $next($request);
        }
//        return response("Insufficient permissions", 401);
        return response(view('error'),401);
    }

}

指数:

     <form class="form-horizontal" action="{{ route('login') }}" method="post">
   {{ csrf_token() }}
   <div class="form-group m-b-20 row">
      <div class="col-12">
         <label for="emailaddress">Username</label>
         <input class="form-control" type="text" id="username" required="" placeholder="Enter Username">
      </div>
   </div>
   <div class="form-group row m-b-20">
      <div class="col-12">
         <label for="password">Password</label>
         <input class="form-control" type="password" required="" id="password" placeholder="Enter your password">
      </div>
   </div>
   <div class="form-group row text-center m-t-10">
      <div class="col-12">
         <button class="btn btn-md btn-block btn-primary waves-effect waves-light" type="submit">Login</button>
      </div>
   </div>
</form>
php laravel laravel-5.5 laravel-5.6
5个回答
3
投票

您可以通过修改以下值来更改config / session.php中Laravel config中的会话生存期

一生

你也需要跑

php artisan config:cache

为Laravel选择新的配置。


0
投票

我已经弄清楚了我是从头开始做的,这是Auth功能的问题导入Auth之前我确实运行了两个命令来清除我的缓存

php artisan cache:clear

php artisan config:cache


and import Auth 

谢谢你帮助的人们欣赏它


0
投票

在$除了VerifyCsrfToken.php中间件的数组之外添加您的路由,例如$ except = [“/ login”]; 。


0
投票

打开VerifyCsrfToken.php中间件并输入除了你的网址之外:

protected $except = [
'http://localhost:8000/login' 

];

并且可以查看laravel文档以获取有关csrf https://laravel.com/docs/5.6/csrf#csrf-excluding-uris的更多信息


-1
投票

我在Laravel 5.6上遇到了同样的问题。解决方案只是添加{{csrf_field()}}

© www.soinside.com 2019 - 2024. All rights reserved.