modified 规范缓存前缀,便于缓存管理

This commit is contained in:
zhaoxiang 2018-03-10 16:07:37 +08:00
parent 6765660167
commit a029b4f05d
6 changed files with 10 additions and 10 deletions

View File

@ -26,8 +26,8 @@ class AdminLog {
$header = config('apiAdmin.CROSS_DOMAIN'); $header = config('apiAdmin.CROSS_DOMAIN');
$request = Request::instance(); $request = Request::instance();
$route = $request->routeInfo(); $route = $request->routeInfo();
$userToken = $request->header('ApiAuth', ''); $ApiAuth = $request->header('ApiAuth', '');
$userInfo = cache($userToken); $userInfo = cache('Login:' . $ApiAuth);
$userInfo = json_decode($userInfo, true); $userInfo = json_decode($userInfo, true);
$menuInfo = AdminMenu::get(['url' => $route['route']]); $menuInfo = AdminMenu::get(['url' => $route['route']]);

View File

@ -23,7 +23,7 @@ class ApiAuth {
$header = config('apiAdmin.CROSS_DOMAIN'); $header = config('apiAdmin.CROSS_DOMAIN');
$ApiAuth = $request->header('ApiAuth', ''); $ApiAuth = $request->header('ApiAuth', '');
if ($ApiAuth) { if ($ApiAuth) {
$userInfo = cache($ApiAuth); $userInfo = cache('Login:' . $ApiAuth);
$userInfo = json_decode($userInfo, true); $userInfo = json_decode($userInfo, true);
if (!$userInfo || !isset($userInfo['id'])) { if (!$userInfo || !isset($userInfo['id'])) {
$data = ['code' => ReturnCode::AUTH_ERROR, 'msg' => 'ApiAuth不匹配', 'data' => []]; $data = ['code' => ReturnCode::AUTH_ERROR, 'msg' => 'ApiAuth不匹配', 'data' => []];

View File

@ -30,7 +30,7 @@ class ApiPermission {
$route = $request->routeInfo(); $route = $request->routeInfo();
$header = config('apiAdmin.CROSS_DOMAIN'); $header = config('apiAdmin.CROSS_DOMAIN');
$ApiAuth = $request->header('ApiAuth', ''); $ApiAuth = $request->header('ApiAuth', '');
$userInfo = cache($ApiAuth); $userInfo = cache('Login:' . $ApiAuth);
$userInfo = json_decode($userInfo, true); $userInfo = json_decode($userInfo, true);
if (!$this->checkAuth($userInfo['id'], $route['route'])) { if (!$this->checkAuth($userInfo['id'], $route['route'])) {
$data = ['code' => ReturnCode::INVALID, 'msg' => '非常抱歉,您没有权限怎么做!', 'data' => []]; $data = ['code' => ReturnCode::INVALID, 'msg' => '非常抱歉,您没有权限怎么做!', 'data' => []];

View File

@ -17,7 +17,7 @@ class Base extends Controller {
public function _initialize() { public function _initialize() {
$ApiAuth = $this->request->header('ApiAuth'); $ApiAuth = $this->request->header('ApiAuth');
if ($ApiAuth) { if ($ApiAuth) {
$userInfo = cache($ApiAuth); $userInfo = cache('Login:' . $ApiAuth);
$this->userInfo = json_decode($userInfo, true); $this->userInfo = json_decode($userInfo, true);
} }
} }

View File

@ -64,8 +64,8 @@ class Login extends Base {
return $this->buildFailed(ReturnCode::LOGIN_ERROR, '用户名密码不正确'); return $this->buildFailed(ReturnCode::LOGIN_ERROR, '用户名密码不正确');
} }
$apiAuth = md5(uniqid() . time()); $apiAuth = md5(uniqid() . time());
cache($apiAuth, json_encode($userInfo), config('apiAdmin.ONLINE_TIME')); cache('Login:' . $apiAuth, json_encode($userInfo), config('apiAdmin.ONLINE_TIME'));
cache($userInfo['id'], $apiAuth, config('apiAdmin.ONLINE_TIME')); cache('Login:' . $userInfo['id'], $apiAuth, config('apiAdmin.ONLINE_TIME'));
$return['access'] = 1000000; $return['access'] = 1000000;
$isSupper = Tools::isAdministrator($userInfo['id']); $isSupper = Tools::isAdministrator($userInfo['id']);
@ -92,8 +92,8 @@ class Login extends Base {
public function logout() { public function logout() {
$ApiAuth = $this->request->header('ApiAuth'); $ApiAuth = $this->request->header('ApiAuth');
cache($ApiAuth, null); cache('Login:' . $ApiAuth, null);
cache($this->userInfo['id'], null); cache('Login:' . $this->userInfo['id'], null);
return $this->buildSuccess([], '登出成功'); return $this->buildSuccess([], '登出成功');
} }

View File

@ -191,7 +191,7 @@ return [
// 缓存保存目录 // 缓存保存目录
'path' => CACHE_PATH, 'path' => CACHE_PATH,
// 缓存前缀 // 缓存前缀
'prefix' => '', 'prefix' => 'ApiAdmin:',
// 缓存有效期 0表示永久缓存 // 缓存有效期 0表示永久缓存
'expire' => 0, 'expire' => 0,
], ],