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