search

Home  >  Q&A  >  body text

Redirect - Laravel 5.2 The session is lost after the middleware redirects to verify login timeout?

public function handle($request, Closure $next, $guard = 'manager')

{
    if (!Auth::guard($guard)->check()) {
        return redirect('manager/login');
    }
    if (config('misc.session_timeout_status')) {
        $isLoggedIn = $request->path() != '/manager/logout';
        if (!session('lastActivityTime')) {
            $this->session->put('lastActivityTime', time());
        } elseif (time() - $this->session->get('lastActivityTime') > $this->timeout) {
            debugbar()->info('时间到!'.$this->timeout);
            log::info('时间到!'.$this->timeout);
            $this->session->forget('lastActivityTime');

            $cookie = cookie('intend', $isLoggedIn ? url()->current() : 'manager/');
            $email  = Auth::guard($guard)->user()->email;
            session()->flash('flash_danger', '您自动登出是出于安全原因,因为您' . $this->timeout / 60 . '分钟内没有活动。');
            Auth::guard($guard)->logout();

            return redirect()->to('/manager/login')->withErrors('您自动登出是出于安全原因,因为您' . $this->timeout / 60 . '分钟内没有活动。')->withInput(compact('email'))->withCookie($cookie);
        }
        $isLoggedIn ? $this->session->put('lastActivityTime', time()) : $this->session->forget('lastActivityTime');
    }

    return $next($request);
}

redirect后session或error都没值了,login接收不到数据,路由如下:

Route::group(['namespace' => 'Manager', 'prefix' => 'manager'], function () {

Route::auth();

Route::group([
    'middleware' => ['admin'],
], function () {
    Route::get('/', 'HomeController@index');
    Route::resource('article', 'ArticleController');       
});

});

不知道哪里出问题了。
过去多啦不再A梦过去多啦不再A梦2750 days ago1176

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2017-05-16 16:53:22

    Middle component 'middleware' => ['admin'], caused

    reply
    0
  • Cancelreply