ebf79d0355
21D — 后端: - Claims 新增 LicenseExpiresAt (*int64 unix 秒),写入 JWT 避免每次查库 - middleware/license_guard.go: CalcLicensePhase / LicenseGuard / GetLicensePhase - grace(0-7d): 允许通行 - readonly(7-15d): 拦截非 GET 写操作 → 403 - locked(15d+): 全部拦截 → 403 - auth.go: issueTokens 在 JWT 中嵌入 license expires_at;Login 检查 locked 拒绝登录 - router: license/* 路由豁免 LicenseGuard(锁定时仍可激活/查状态) 21E — Flutter 前端: - models/license.dart: 新 LicenseInfo,含 phase/maxDevices,去掉旧 activatedAt - core/device/device_id.dart: 持久化 UUID-v4 作为设备 ID(SharedPreferences) - repositories/license_repository.dart: getInfo/activate/deactivate,激活时携带设备信息 - providers/license_provider.dart: 改接 LicenseRepository - settings_screen.dart: activatedAt 改为显示 maxDevices Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
56 lines
1.7 KiB
Dart
56 lines
1.7 KiB
Dart
import 'package:dio/dio.dart';
|
|
import '../core/api/api_client.dart';
|
|
import '../core/device/device_id.dart';
|
|
import '../core/exceptions.dart';
|
|
import '../models/license.dart';
|
|
|
|
class LicenseRepository {
|
|
final ApiClient _client;
|
|
const LicenseRepository(this._client);
|
|
|
|
Future<LicenseInfo?> getInfo() async {
|
|
try {
|
|
final resp = await _client.get('/license/info');
|
|
final data = resp.data['data'];
|
|
if (data == null) return null;
|
|
return LicenseInfo.fromJson(data as Map<String, dynamic>);
|
|
} on DioException catch (e) {
|
|
throw AppException(
|
|
e.response?.data?['error'] as String? ?? '获取授权信息失败',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Activate a license key for this device.
|
|
Future<void> activate(String licenseKey, {String? deviceName}) async {
|
|
final deviceId = await DeviceId.get();
|
|
try {
|
|
await _client.post('/license/activate', data: {
|
|
'license_key': licenseKey,
|
|
'device_id': deviceId,
|
|
'device_name': deviceName ?? DeviceId.platformName,
|
|
'platform': DeviceId.platformName,
|
|
});
|
|
} on DioException catch (e) {
|
|
throw AppException(
|
|
e.response?.data?['error'] as String? ?? '激活失败',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Deactivate (unbind) this device from its license.
|
|
Future<void> deactivate() async {
|
|
final deviceId = await DeviceId.get();
|
|
try {
|
|
await _client.post('/license/deactivate', data: {'device_id': deviceId});
|
|
} on DioException catch (e) {
|
|
throw AppException(
|
|
e.response?.data?['error'] as String? ?? '解绑失败',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
}
|