up
This commit is contained in:
@@ -19,12 +19,18 @@ class Admin
|
||||
*/
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
// 获取路径信息
|
||||
$pathinfo = $request->pathinfo();
|
||||
|
||||
// 判断是否为API请求(非index页面)
|
||||
$isApiRequest = $pathinfo !== 'admin' && strpos($pathinfo, 'admin/') === 0;
|
||||
|
||||
// 检查是否已登录
|
||||
$username = Session::get('username');
|
||||
|
||||
if (empty($username)) {
|
||||
// 如果是AJAX请求,返回JSON
|
||||
if ($request->isAjax()) {
|
||||
// 如果是API请求,返回JSON
|
||||
if ($isApiRequest || $request->isAjax()) {
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => '请先登录',
|
||||
@@ -38,8 +44,8 @@ class Admin
|
||||
$isAdmin = Session::get('is_admin', false);
|
||||
|
||||
if (!$isAdmin) {
|
||||
// 如果是AJAX请求,返回JSON
|
||||
if ($request->isAjax()) {
|
||||
// 如果是API请求,返回JSON
|
||||
if ($isApiRequest || $request->isAjax()) {
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => '无权限访问,需要管理员权限',
|
||||
|
||||
Reference in New Issue
Block a user