mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-24 18:30:18 +08:00
modified 添加部分数据
This commit is contained in:
parent
cad2716183
commit
40523ef98a
@ -19,7 +19,7 @@ use app\util\Tools;
|
|||||||
class Login extends Base {
|
class Login extends Base {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户登录
|
* 用户登录【账号密码登录】
|
||||||
* @return array
|
* @return array
|
||||||
* @throws \think\Exception
|
* @throws \think\Exception
|
||||||
* @throws \think\exception\DbException
|
* @throws \think\exception\DbException
|
||||||
@ -40,13 +40,12 @@ class Login extends Base {
|
|||||||
if (!empty($userInfo)) {
|
if (!empty($userInfo)) {
|
||||||
if ($userInfo['status']) {
|
if ($userInfo['status']) {
|
||||||
//更新用户数据
|
//更新用户数据
|
||||||
$userData = AdminUserData::get(['uid' => $userInfo['id']]);
|
$userData = $userInfo->userData;
|
||||||
$data = [];
|
$data = [];
|
||||||
if ($userData) {
|
if ($userData) {
|
||||||
$userData->login_times++;
|
$userData->login_times++;
|
||||||
$userData->last_login_ip = $this->request->ip(1);
|
$userData->last_login_ip = $this->request->ip(1);
|
||||||
$userData->last_login_time = time();
|
$userData->last_login_time = time();
|
||||||
$return['head_img'] = $userData['head_img'];
|
|
||||||
$userData->save();
|
$userData->save();
|
||||||
} else {
|
} else {
|
||||||
$data['login_times'] = 1;
|
$data['login_times'] = 1;
|
||||||
@ -54,8 +53,9 @@ class Login extends Base {
|
|||||||
$data['last_login_ip'] = $this->request->ip(1);
|
$data['last_login_ip'] = $this->request->ip(1);
|
||||||
$data['last_login_time'] = time();
|
$data['last_login_time'] = time();
|
||||||
$data['head_img'] = '';
|
$data['head_img'] = '';
|
||||||
$return['head_img'] = '';
|
|
||||||
AdminUserData::create($data);
|
AdminUserData::create($data);
|
||||||
|
|
||||||
|
$userInfo['userData'] = $data;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return $this->buildFailed(ReturnCode::LOGIN_ERROR, '用户已被封禁,请联系管理员');
|
return $this->buildFailed(ReturnCode::LOGIN_ERROR, '用户已被封禁,请联系管理员');
|
||||||
@ -67,27 +67,32 @@ class Login extends Base {
|
|||||||
cache('Login:' . $apiAuth, json_encode($userInfo), config('apiadmin.ONLINE_TIME'));
|
cache('Login:' . $apiAuth, json_encode($userInfo), config('apiadmin.ONLINE_TIME'));
|
||||||
cache('Login:' . $userInfo['id'], $apiAuth, config('apiadmin.ONLINE_TIME'));
|
cache('Login:' . $userInfo['id'], $apiAuth, config('apiadmin.ONLINE_TIME'));
|
||||||
|
|
||||||
$return['access'] = [];
|
$userInfo['access'] = [];
|
||||||
$isSupper = Tools::isAdministrator($userInfo['id']);
|
$isSupper = Tools::isAdministrator($userInfo['id']);
|
||||||
if ($isSupper) {
|
if ($isSupper) {
|
||||||
$access = AdminMenu::all(['hide' => 0]);
|
$access = AdminMenu::all(['hide' => 0]);
|
||||||
$access = Tools::buildArrFromObj($access);
|
$access = Tools::buildArrFromObj($access);
|
||||||
$return['access'] = array_values(array_filter(array_column($access, 'url')));
|
$userInfo['access'] = array_values(array_filter(array_column($access, 'url')));
|
||||||
} else {
|
} else {
|
||||||
$groups = AdminAuthGroupAccess::get(['uid' => $userInfo['id']]);
|
$groups = AdminAuthGroupAccess::get(['uid' => $userInfo['id']]);
|
||||||
if (isset($groups) && $groups->group_id) {
|
if (isset($groups) && $groups->group_id) {
|
||||||
$access = (new AdminAuthRule())->whereIn('group_id', $groups->group_id)->select();
|
$access = (new AdminAuthRule())->whereIn('group_id', $groups->group_id)->select();
|
||||||
$access = Tools::buildArrFromObj($access);
|
$access = Tools::buildArrFromObj($access);
|
||||||
$return['access'] = array_values(array_unique(array_column($access, 'url')));
|
$userInfo['access'] = array_values(array_unique(array_column($access, 'url')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$userInfo['apiAuth'] = $apiAuth;
|
||||||
|
|
||||||
$return['id'] = $userInfo['id'];
|
return $this->buildSuccess($userInfo, '登录成功');
|
||||||
$return['username'] = $userInfo['username'];
|
}
|
||||||
$return['nickname'] = $userInfo['nickname'];
|
|
||||||
$return['apiAuth'] = $apiAuth;
|
|
||||||
|
|
||||||
return $this->buildSuccess($return, '登录成功');
|
/**
|
||||||
|
* 获取用户信息
|
||||||
|
* @return mixed
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
public function getUserInfo() {
|
||||||
|
return $this->userInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function logout() {
|
public function logout() {
|
||||||
|
@ -16,6 +16,7 @@ Route::group('admin', function () {
|
|||||||
Route::rule('Login/index','admin/Login/index','post');
|
Route::rule('Login/index','admin/Login/index','post');
|
||||||
Route::rule('Index/upload','admin/Index/upload','post');
|
Route::rule('Index/upload','admin/Index/upload','post');
|
||||||
Route::rule('Login/logout','admin/Login/logout','get');
|
Route::rule('Login/logout','admin/Login/logout','get');
|
||||||
|
Route::rule('Login/getUserInfo','admin/Login/getUserInfo','get')->middleware(['AdminAuth', 'AdminPermission', 'AdminLog']);
|
||||||
|
|
||||||
//大部分控制器的路由都以分组的形式写到这里
|
//大部分控制器的路由都以分组的形式写到这里
|
||||||
Route::group('Menu', [
|
Route::group('Menu', [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user