更新命名问题
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
@@ -44,6 +45,14 @@ abstract class BaseController
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [];
|
||||
protected $module;
|
||||
protected $controller;
|
||||
protected $action;
|
||||
protected $param;
|
||||
protected $uid;
|
||||
protected $did;
|
||||
protected $name;
|
||||
|
||||
|
||||
/**
|
||||
* 分页数量
|
||||
@@ -73,13 +82,11 @@ abstract class BaseController
|
||||
protected function initialize()
|
||||
{
|
||||
// 检测权限
|
||||
// $this->checkLogin();
|
||||
//每页显示数据量
|
||||
$this->pageSize = Request::param('page_size', \think\facade\Config::get('app.page_size'));
|
||||
//显示当前登录账户权限
|
||||
// $this->showLoginUserInfo();
|
||||
$this->checkLogin();
|
||||
$this->param = $this->request->param();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 显示当前登录账户信息
|
||||
*/
|
||||
@@ -98,14 +105,71 @@ abstract class BaseController
|
||||
*/
|
||||
protected function checkLogin()
|
||||
{
|
||||
$session_admin = get_config('app.session_admin');
|
||||
if (!Session::has($session_admin)) {
|
||||
$this->apiError('请先登录');
|
||||
} else {
|
||||
$this->uid = Session::get($session_admin)['id'];
|
||||
View::assign('login_user', $this->uid);
|
||||
// 定义一个不需要登录验证的接口白名单
|
||||
$noNeedLogin = [
|
||||
'apiout/businessinfo/product_info',
|
||||
'apiout/businessinfo/bifill',
|
||||
'apiout/index/getpicbedfolder',
|
||||
'apiout/download/catelist',
|
||||
'apiout/download/cateinfo',
|
||||
];
|
||||
|
||||
// 当前请求的路径
|
||||
$currentPath = $this->module . '/' . $this->controller . '/' . $this->action;
|
||||
|
||||
// 检查当前路径是否在白名单中
|
||||
if (in_array($currentPath, $noNeedLogin)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->controller !== 'login' && $this->controller !== 'captcha') {
|
||||
$session_admin = get_config('app.session_admin');
|
||||
if (!Session::has($session_admin)) {
|
||||
if ($this->request->isAjax()) {
|
||||
return to_assign(404, '请先登录');
|
||||
} else {
|
||||
// redirect('/home/login/index.html')->send();
|
||||
// exit;
|
||||
return to_assign(404, '请先登录');
|
||||
}
|
||||
} else {
|
||||
$loginUser = Session::get($session_admin);
|
||||
$loginInfo = Db::name('Admin')->where('id', $loginUser['id'])->find();
|
||||
$this->uid = $loginInfo['id'];
|
||||
|
||||
$params = [
|
||||
'uid' => $this->uid,
|
||||
'name' => $loginInfo['name'],
|
||||
'thumb' => $loginInfo['thumb'],
|
||||
'module' => $this->module,
|
||||
'controller' => $this->controller,
|
||||
'action' => $this->action,
|
||||
'url' => $this->module . '/' . $this->controller . '/' . $this->action,
|
||||
'version' => get_system_config('web', 'version')
|
||||
];
|
||||
View::assign('params', $params);
|
||||
// 验证用户访问权限
|
||||
if (($this->module == 'api') || ($this->module == 'home') || ($this->module == 'apiout')) {
|
||||
return true;
|
||||
} else {
|
||||
$reg_pwd = Db::name('Admin')->where(['id' => $this->uid])->value('reg_pwd');
|
||||
if ($reg_pwd !== '') {
|
||||
redirect('/home/user/edit_password.html')->send();
|
||||
exit;
|
||||
}
|
||||
if (!$this->checkAuth()) {
|
||||
if ($this->request->isAjax()) {
|
||||
return to_assign(202, '你没有权限,请联系管理员或者人事部');
|
||||
} else {
|
||||
echo '<div style="text-align:center;color:red;margin-top:20%;">你没有权限,请联系管理员或者人事部</div>';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Api处理成功结果返回方法
|
||||
* @param $message
|
||||
@@ -156,5 +220,4 @@ abstract class BaseController
|
||||
|
||||
throw new HttpResponseException($response);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user