mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified 优化用户数据获取
This commit is contained in:
parent
05ee080d1a
commit
54c77736e5
@ -63,24 +63,12 @@ class Login extends Base {
|
||||
} else {
|
||||
return $this->buildFailed(ReturnCode::LOGIN_ERROR, '用户名密码不正确');
|
||||
}
|
||||
$userInfo['access'] = $this->getAccess($userInfo['id']);
|
||||
|
||||
$apiAuth = md5(uniqid() . time());
|
||||
cache('Login:' . $apiAuth, json_encode($userInfo), config('apiadmin.ONLINE_TIME'));
|
||||
cache('Login:' . $userInfo['id'], $apiAuth, config('apiadmin.ONLINE_TIME'));
|
||||
|
||||
$userInfo['access'] = [];
|
||||
$isSupper = Tools::isAdministrator($userInfo['id']);
|
||||
if ($isSupper) {
|
||||
$access = AdminMenu::all(['hide' => 0]);
|
||||
$access = Tools::buildArrFromObj($access);
|
||||
$userInfo['access'] = array_values(array_filter(array_column($access, 'url')));
|
||||
} else {
|
||||
$groups = AdminAuthGroupAccess::get(['uid' => $userInfo['id']]);
|
||||
if (isset($groups) && $groups->group_id) {
|
||||
$access = (new AdminAuthRule())->whereIn('group_id', $groups->group_id)->select();
|
||||
$access = Tools::buildArrFromObj($access);
|
||||
$userInfo['access'] = array_values(array_unique(array_column($access, 'url')));
|
||||
}
|
||||
}
|
||||
$userInfo['apiAuth'] = $apiAuth;
|
||||
|
||||
return $this->buildSuccess($userInfo, '登录成功');
|
||||
@ -92,7 +80,7 @@ class Login extends Base {
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
public function getUserInfo() {
|
||||
return $this->userInfo;
|
||||
return $this->buildSuccess($this->userInfo);
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
@ -103,4 +91,30 @@ class Login extends Base {
|
||||
return $this->buildSuccess([], '登出成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户权限数据
|
||||
* @param $uid
|
||||
* @return array
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
private function getAccess($uid) {
|
||||
$isSupper = Tools::isAdministrator($uid);
|
||||
if ($isSupper) {
|
||||
$access = AdminMenu::all(['hide' => 0]);
|
||||
$access = Tools::buildArrFromObj($access);
|
||||
|
||||
return array_values(array_filter(array_column($access, 'url')));
|
||||
} else {
|
||||
$groups = AdminAuthGroupAccess::get(['uid' => $uid]);
|
||||
if (isset($groups) && $groups->group_id) {
|
||||
$access = (new AdminAuthRule())->whereIn('group_id', $groups->group_id)->select();
|
||||
$access = Tools::buildArrFromObj($access);
|
||||
|
||||
return array_values(array_unique(array_column($access, 'url')));
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ return [
|
||||
'CROSS_DOMAIN' => [
|
||||
'Access-Control-Allow-Origin' => '*',
|
||||
'Access-Control-Allow-Methods' => 'POST,PUT,GET,DELETE',
|
||||
'Access-Control-Allow-Headers' => 'version, access-token, user-token, ApiAuth, User-Agent, Keep-Alive, Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With',
|
||||
'Access-Control-Allow-Headers' => 'version, access-token, user-token, apiAuth, User-Agent, Keep-Alive, Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With',
|
||||
'Access-Control-Allow-Credentials' => 'true'
|
||||
],
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user