1.优化设备只能登录一个

This commit is contained in:
2026-05-29 14:19:24 +08:00
parent 1df1396b44
commit 4324c19d30
8 changed files with 217 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ namespace app\api\controller;
use app\common\controller\Frontend;
use app\common\facade\Token;
use app\common\service\MobileAuthDeviceService;
use support\Response;
use Webman\Http\Request;
use function response;
@@ -28,6 +29,7 @@ abstract class MobileBase extends Frontend
$parts = explode('/', $path);
$action = $parts[array_key_last($parts)] ?? '';
$needAuthToken = !action_in_arr($this->noNeedAuthToken, $action);
$authToken = '';
if ($needAuthToken) {
$authToken = trim((string) $request->header('auth-token', ''));
if ($authToken === '') {
@@ -41,7 +43,20 @@ abstract class MobileBase extends Frontend
}
}
return $this->initializeFrontend($request);
$response = $this->initializeFrontend($request);
if ($response !== null) {
return $response;
}
$needLogin = !action_in_arr($this->noNeedLogin, $action);
if ($needAuthToken && $needLogin && $this->auth->isLogin()) {
$deviceError = MobileAuthDeviceService::validateUserDeviceSession($authToken, (int) $this->auth->id);
if ($deviceError !== null) {
return $this->mobileError(1101, $deviceError);
}
}
return null;
}
protected function mobileSuccess(array $data = [], string $message = 'ok'): Response