mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-08 19:12:48 +08:00
refactor: 重构用户信息状态代码写法。
This commit is contained in:
@@ -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