diff --git a/app/common/controller/AuthController.php b/app/common/controller/AuthController.php index f85d520..34beb91 100644 --- a/app/common/controller/AuthController.php +++ b/app/common/controller/AuthController.php @@ -67,10 +67,10 @@ class AuthController extends BaseController try { $data = $request->all(); - if(empty($data['feishu_code']) || empty($data['app_id'])){ + $data['login_type'] = $request->login_type; + if($data['login_type'] == 'feishu' && (empty($data['feishu_code']) || empty($data['app_id']))){ throw new BusinessException('参数错误'); } - $result = (new AuthService())->login($data); return $this->success($result, '登录成功'); } catch (\Throwable $e) { diff --git a/app/common/controller/PresetController.php b/app/common/controller/PresetController.php new file mode 100644 index 0000000..f7c72f1 --- /dev/null +++ b/app/common/controller/PresetController.php @@ -0,0 +1,32 @@ +select(['id','name','app_id'])->get(); + return $this->success($fsAppInfo); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/common/logic/AuthLogic.php b/app/common/logic/AuthLogic.php index fad60df..ae482ac 100644 --- a/app/common/logic/AuthLogic.php +++ b/app/common/logic/AuthLogic.php @@ -23,10 +23,10 @@ class AuthLogic public function uPwdLogin(array $data): array { $user = $this->validateUser($data['account'], $data['password']); - $system = $this->validateSystem($data['system_code']); - $this->validateSystemPermission($user, $system); + //$system = $this->validateSystem($data['system_code']); + //$this->validateSystemPermission($user, $system); - return $this->generateTokensAndReturn($user, $system, $data); + return $this->generateTokensAndReturn($user, $data); } /** @@ -37,14 +37,14 @@ class AuthLogic { $feishuUserInfo = $this->getFeishuUserInfo($data); return $feishuUserInfo; - $user = $this->getOrCreateUser($feishuUserInfo); - - $system = $this->validateSystem($data['system_code']); - if ($user->isLogin) { - $this->validateSystemPermission($user, $system); - } - - return $this->generateTokensAndReturn($user, $system, $data); +// $user = $this->getOrCreateUser($feishuUserInfo); +// +// $system = $this->validateSystem($data['system_code']); +// if ($user->isLogin) { +// $this->validateSystemPermission($user, $system); +// } +// +// return $this->generateTokensAndReturn($user, $system, $data); } /** @@ -168,24 +168,16 @@ class AuthLogic /** * 生成并记录token,返回包含token的响应数据 */ - private function generateTokensAndReturn(User $user, Systems $system, array $data): array + private function generateTokensAndReturn(User $user, array $data): array { - $payload = $this->buildJwtPayload($user, $system); - $token = $this->generateAccessToken($payload); - $refreshToken = $this->generateRefreshToken($user->id, $data['system_code']); - $homeUrl = $this->getHome($system->id, $payload); +// $refreshToken = $this->generateRefreshToken($user->id, $data['system_code']); - // 记录 token 到 Redis 和 MySQL - $this->recordUserToken($user->id, $token, $data['system_code']); return [ - 'access_token' => $token, - 'refresh_token' => $refreshToken, - 'expires_in' => config('jwt.jwt_expiration'), - 'system_code' => $data['system_code'], - 'corp_abbr' => $data['corp_abbr'], + 'union_id' => $user->union_id, + 'role' => $user->role, + 'role_wp' => $user->role_wp, 'login_type' => $data['login_type'], - 'home_url' => $homeUrl, // 'payload' => $payload, ]; } diff --git a/app/common/model/User.php b/app/common/model/User.php index 341b5b5..4d81c2d 100644 --- a/app/common/model/User.php +++ b/app/common/model/User.php @@ -46,4 +46,11 @@ class User extends Model * 不允许自动填充模型字段 */ protected $guarded = []; + + // 账号查询的作用域 + public function scopeByAccount($query, $account) + { + return $query->Where('phone', $account) + ->orWhere('email', $account); + } } \ No newline at end of file diff --git a/config/route.php b/config/route.php index 7da2110..6053637 100644 --- a/config/route.php +++ b/config/route.php @@ -41,6 +41,9 @@ Route::any('/upload/delete', [app\common\controller\UploadController::class, 'de // 公共 Route::group('/common', function () { + Route::group('/preset', function () { + Route::any('/corps', [app\common\controller\PresetController::class, 'corps']); + }); Route::group('/auth', function () { Route::any('/login', [app\common\controller\AuthController::class, 'login']); Route::any('/feishu/scope', [app\common\controller\AuthController::class, 'feishuScope']);