<?php
 namespace Module\Member\Middleware; use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\View; use ModStart\Core\Input\Request; use ModStart\Core\Input\Response; use Module\Member\Support\MemberLoginCheck; use Module\Member\Util\MemberUtil; class WebAuthMiddleware { public function handle($request, \Closure $next) { list($controller, $action) = Request::getControllerAction(); $memberUserId = intval(Session::get('memberUserId', 0)); $memberUser = null; if ($memberUserId) { $memberUser = MemberUtil::get($memberUserId); } if ($memberUserId && !$memberUser) { $memberUserId = 0; Session::forget('memberUserId'); } View::share('_memberUserId', $memberUserId); if (empty($memberUserId)) { if (is_subclass_of($controller, MemberLoginCheck::class)) { return Response::send(-1, null, null, '/login?redirect=' . urlencode(Request::currentPageUrl())); } } Session::put('memberUserId', $memberUserId); Session::flash('_memberUser', $memberUser); View::share('_memberUser', $memberUser); return $next($request); } }