mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-06 01:52:48 +08:00
refactor: 重构用户信息状态代码写法。
This commit is contained in:
@@ -21,11 +21,11 @@ class AjaxBase extends AdminController
|
||||
*/
|
||||
public function initAdmin()
|
||||
{
|
||||
$cacheData = Cache::get('initAdmin_' . session('admin.id'));
|
||||
$cacheData = Cache::get('initAdmin_' . $this->sessionAdmin->id);
|
||||
if (!empty($cacheData)) {
|
||||
return json($cacheData);
|
||||
}
|
||||
$menuService = new MenuService(session('admin.id'));
|
||||
$menuService = new MenuService($this->sessionAdmin->id);
|
||||
$data = [
|
||||
'logoInfo' => [
|
||||
'title' => sysconfig('site', 'logo_title'),
|
||||
@@ -35,7 +35,7 @@ class AjaxBase extends AdminController
|
||||
'homeInfo' => $menuService->getHomeInfo(),
|
||||
'menuInfo' => $menuService->getMenuTree(),
|
||||
];
|
||||
Cache::tag('initAdmin')->set('initAdmin_' . session('admin.id'), $data);
|
||||
Cache::tag('initAdmin')->set('initAdmin_' . $this->sessionAdmin->id, $data);
|
||||
|
||||
return json($data);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class IndexBase extends AdminController
|
||||
public function index()
|
||||
{
|
||||
return $this->fetch('', [
|
||||
'admin' => session('admin'),
|
||||
'admin' => $this->sessionAdmin,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class IndexBase extends AdminController
|
||||
*/
|
||||
public function editAdmin()
|
||||
{
|
||||
$id = session('admin.id');
|
||||
$id = $this->sessionAdmin->id;
|
||||
$row = (new SystemAdmin())
|
||||
->withoutField('password')
|
||||
->find($id);
|
||||
@@ -96,7 +96,7 @@ class IndexBase extends AdminController
|
||||
*/
|
||||
public function editPassword()
|
||||
{
|
||||
$id = session('admin.id');
|
||||
$id = $this->sessionAdmin->id;
|
||||
$row = (new SystemAdmin())
|
||||
->withoutField('password')
|
||||
->find($id);
|
||||
@@ -140,7 +140,7 @@ class IndexBase extends AdminController
|
||||
{
|
||||
$pid = $this->request->param('pid', 0);
|
||||
|
||||
$menuService = new MenuService(session('admin.id'));
|
||||
$menuService = new MenuService($this->sessionAdmin->id);
|
||||
|
||||
$home_info = $menuService->getHomeInfo();
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class LoginBase extends AdminController
|
||||
{
|
||||
parent::initialize();
|
||||
$action = $this->request->action();
|
||||
if (!empty(session('admin')) && !in_array($action, ['out'])) {
|
||||
if (!empty($this->sessionAdmin) && !in_array($action, ['out'])) {
|
||||
$adminModuleName = config('app.admin_alias_name');
|
||||
$this->success('已登录,无需再次登录', [], __url("@{$adminModuleName}"));
|
||||
}
|
||||
|
||||
@@ -121,8 +121,8 @@ class AdminControllerBase extends BaseController
|
||||
parent::initialize();
|
||||
$this->layout && $this->app->view->engine()->layout($this->layout);
|
||||
$this->isDemo = Env::get('adminsystem.is_demo', false);
|
||||
$this->viewInit();
|
||||
$this->checkAuth();
|
||||
$this->viewInit();
|
||||
|
||||
$this->initSort();
|
||||
}
|
||||
@@ -437,7 +437,7 @@ class AdminControllerBase extends BaseController
|
||||
$autoloadJs = file_exists(root_path('public') . "static/{$thisModule}/js/{$jsPath}.js") ? true : false;
|
||||
$thisControllerJsPath = "{$thisModule}/js/{$jsPath}.js";
|
||||
$adminModuleName = config('app.admin_alias_name');
|
||||
$isSuperAdmin = session('admin.id') == AdminConstant::SUPER_ADMIN_ID ? true : false;
|
||||
$isSuperAdmin = $this->sessionAdmin->id == AdminConstant::SUPER_ADMIN_ID ? true : false;
|
||||
$data = [
|
||||
'adminModuleName' => $adminModuleName,
|
||||
'thisController' => parse_name($thisController),
|
||||
@@ -462,13 +462,7 @@ class AdminControllerBase extends BaseController
|
||||
protected function checkAuth($currentNode = null, $haltRequest = true)
|
||||
{
|
||||
$adminConfig = config('admin');
|
||||
|
||||
$token = $this->readHeaderToken();
|
||||
if (!empty($token)) {
|
||||
$admin = Cache::get($token);
|
||||
} else {
|
||||
$admin = session('admin');
|
||||
}
|
||||
$admin = get_session_admin();
|
||||
|
||||
$back_url = $this->request->url();
|
||||
|
||||
@@ -528,12 +522,7 @@ class AdminControllerBase extends BaseController
|
||||
}
|
||||
|
||||
protected function readHeaderToken(){
|
||||
$header_authorization = $this->request->header('Authorization');
|
||||
if (!empty($header_authorization)) {
|
||||
$token = explode(' ', $header_authorization)[1];
|
||||
return $token;
|
||||
}
|
||||
return null;
|
||||
return read_header_token();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,8 @@ use think\facade\Cache;
|
||||
use think\facade\Env;
|
||||
use think\facade\Event;
|
||||
use think\facade\Filesystem;
|
||||
use think\facade\Request;
|
||||
use think\helper\Arr;
|
||||
use think\response\View;
|
||||
use think\route\Url;
|
||||
|
||||
@@ -175,13 +177,37 @@ if (!function_exists('auth')) {
|
||||
*/
|
||||
function auth($node = null)
|
||||
{
|
||||
$authService = new AuthService(session('admin.id'));
|
||||
$authService = new AuthService(get_session_admin('id'));
|
||||
$check = $authService->checkNode($node);
|
||||
|
||||
return $check;
|
||||
}
|
||||
}
|
||||
|
||||
function get_session_admin($key = null)
|
||||
{
|
||||
$token = read_header_token();
|
||||
if (!empty($token)) {
|
||||
$admin = Cache::get($token);
|
||||
} else {
|
||||
$admin = session('admin');
|
||||
}
|
||||
|
||||
return Arr::get($admin, $key);
|
||||
}
|
||||
|
||||
function read_header_token()
|
||||
{
|
||||
$header_authorization = Request::header('Authorization');
|
||||
if (!empty($header_authorization)) {
|
||||
$token = explode(' ', $header_authorization)[1];
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function json_message($data = [], $code = 0, $msg = '')
|
||||
{
|
||||
if (is_string($data)) {
|
||||
|
||||
Reference in New Issue
Block a user