refactor(out): remove BaseAuth token parsing dependency
Made-with: Cursor
This commit is contained in:
@@ -7,13 +7,12 @@ namespace app\services\out;
|
||||
|
||||
|
||||
use app\dao\out\OutAccountDao;
|
||||
use crmeb\basic\BaseAuth;
|
||||
use app\services\auth\AccessTokenService;
|
||||
use app\services\BaseServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use crmeb\exceptions\AuthException;
|
||||
use crmeb\services\CacheService;
|
||||
use crmeb\services\HttpService;
|
||||
use crmeb\utils\ApiErrorCode;
|
||||
use crmeb\utils\JwtAuth;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
@@ -77,14 +76,15 @@ class OutAccountServices extends BaseServices
|
||||
*/
|
||||
public function parseToken(string $token)
|
||||
{
|
||||
/** @var BaseAuth $services */
|
||||
$services = app()->make(BaseAuth::class);
|
||||
$adminInfo = $services->parseToken($token, function ($id) {
|
||||
return $this->dao->get($id);
|
||||
});
|
||||
if (isset($adminInfo->auth) && $adminInfo->auth !== md5($adminInfo->appsecret)) {
|
||||
throw new AuthException(ApiErrorCode::ERR_LOGIN_INVALID);
|
||||
}
|
||||
/** @var AccessTokenService $services */
|
||||
$services = app()->make(AccessTokenService::class);
|
||||
$adminInfo = $services->parseToken(
|
||||
$token,
|
||||
'out',
|
||||
fn($id) => $this->dao->get($id),
|
||||
fn($adminInfo) => md5($adminInfo->appsecret)
|
||||
);
|
||||
|
||||
return $adminInfo->hidden(['appsecret', 'ip', 'status']);
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ class OutAccountServices extends BaseServices
|
||||
$authInfo = $this->dao->getOne(['id' => $id, 'is_del' => 0]);
|
||||
$this->checkAuth($authInfo, $md5Token, $cacheService);
|
||||
|
||||
$cacheService->delete($md5Token);
|
||||
CacheService::redisHandler('out')->delete($md5Token);
|
||||
|
||||
$token = $jwtAuth->createToken($id, $type);
|
||||
$data['last_time'] = time();
|
||||
@@ -203,7 +203,8 @@ class OutAccountServices extends BaseServices
|
||||
|
||||
$md5Token = md5($token);
|
||||
|
||||
if (!$cacheService->has($md5Token) || !($cacheToken = $cacheService->get($md5Token, '', NULL, 'out'))) {
|
||||
$cacheToken = CacheService::redisHandler('out')->get($md5Token, null);
|
||||
if (!$cacheToken) {
|
||||
throw new AuthException('登录已过期,请重新登录');
|
||||
}
|
||||
|
||||
@@ -217,7 +218,7 @@ class OutAccountServices extends BaseServices
|
||||
$jwtAuth->verifyToken();
|
||||
} catch (\Throwable $e) {
|
||||
if (!request()->isCli()) {
|
||||
$cacheService->delete($md5Token);
|
||||
CacheService::redisHandler('out')->delete($md5Token);
|
||||
}
|
||||
throw new AuthException('登录失败');
|
||||
}
|
||||
@@ -236,14 +237,14 @@ class OutAccountServices extends BaseServices
|
||||
{
|
||||
if (!$authInfo) {
|
||||
if (!request()->isCli()) {
|
||||
$cacheService->delete($md5Token);
|
||||
CacheService::redisHandler('out')->delete($md5Token);
|
||||
}
|
||||
throw new AuthException('登录已过期,请重新登录');
|
||||
}
|
||||
|
||||
if ($authInfo->status == 2) {
|
||||
if (!request()->isCli()) {
|
||||
$cacheService->delete($md5Token);
|
||||
CacheService::redisHandler('out')->delete($md5Token);
|
||||
}
|
||||
throw new AuthException('您已被禁止登录');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user