feat(security): 加固令牌与会话隔离,完善局域网授权与相册分页
- 令牌改用安全存储持久化,登录/登出按会话版本重建 ProviderScope 并清理账号缓存 - dio 401 刷新改为并发共享单次刷新,避免旧会话覆盖新账号令牌 - Android 17 增加局域网权限申请与网络安全配置,iOS 补充本地网络说明与钥匙串权限 - 相册分页加载并及时释放缩略图/媒体缓存,远程连接销毁时释放信令与 WebRTC - 升级 AGP 9 / Gradle 9 / compileSdk 37,统一第三方插件 compileSdk,Windows 启用 /utf-8 - 新增 dio 刷新、会话隔离与相册分页单元测试
This commit is contained in:
1 parent
7435588fa7
commit
4976a26892
41 files changed
+1232
-654
No files matched your search
@@ -5,7 +5,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/network/api_exception.dart';
|
||||
import '../../../core/network/error_message.dart';
|
||||
import '../../../core/storage/token_storage.dart';
|
||||
import '../../device/data/device_providers.dart';
|
||||
import '../data/auth_providers.dart';
|
||||
import '../domain/auth_models.dart';
|
||||
import '../domain/auth_state.dart';
|
||||
@@ -33,23 +32,24 @@ class AuthController extends Notifier<AuthState> {
|
||||
required String phone,
|
||||
required String password,
|
||||
}) async {
|
||||
return _run(() => ref.read(authRepositoryProvider).loginByPassword(
|
||||
phone: phone,
|
||||
password: password,
|
||||
deviceId: _deviceId,
|
||||
));
|
||||
return _run(
|
||||
() => ref
|
||||
.read(authRepositoryProvider)
|
||||
.loginByPassword(
|
||||
phone: phone,
|
||||
password: password,
|
||||
deviceId: _deviceId,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 短信登录。
|
||||
Future<bool> loginBySms({
|
||||
required String phone,
|
||||
required String code,
|
||||
}) async {
|
||||
return _run(() => ref.read(authRepositoryProvider).loginBySms(
|
||||
phone: phone,
|
||||
code: code,
|
||||
deviceId: _deviceId,
|
||||
));
|
||||
Future<bool> loginBySms({required String phone, required String code}) async {
|
||||
return _run(
|
||||
() => ref
|
||||
.read(authRepositoryProvider)
|
||||
.loginBySms(phone: phone, code: code, deviceId: _deviceId),
|
||||
);
|
||||
}
|
||||
|
||||
/// 注册。
|
||||
@@ -58,12 +58,16 @@ class AuthController extends Notifier<AuthState> {
|
||||
required String code,
|
||||
required String password,
|
||||
}) async {
|
||||
return _run(() => ref.read(authRepositoryProvider).register(
|
||||
phone: phone,
|
||||
code: code,
|
||||
password: password,
|
||||
deviceId: _deviceId,
|
||||
));
|
||||
return _run(
|
||||
() => ref
|
||||
.read(authRepositoryProvider)
|
||||
.register(
|
||||
phone: phone,
|
||||
code: code,
|
||||
password: password,
|
||||
deviceId: _deviceId,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 发送短信验证码并启动 60s 倒计时。
|
||||
@@ -83,16 +87,12 @@ class AuthController extends Notifier<AuthState> {
|
||||
}
|
||||
state = state.copyWith(isSendingCode: true, clearAlert: true);
|
||||
try {
|
||||
await ref.read(authRepositoryProvider).sendSmsCode(
|
||||
phone: trimmed,
|
||||
scene: scene,
|
||||
);
|
||||
await ref
|
||||
.read(authRepositoryProvider)
|
||||
.sendSmsCode(phone: trimmed, scene: scene);
|
||||
_startCountdown();
|
||||
} catch (e) {
|
||||
state = state.copyWith(
|
||||
isSendingCode: false,
|
||||
alert: userMessageOf(e),
|
||||
);
|
||||
state = state.copyWith(isSendingCode: false, alert: userMessageOf(e));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,11 +112,9 @@ class AuthController extends Notifier<AuthState> {
|
||||
}) async {
|
||||
state = state.copyWith(isLoading: true, clearAlert: true);
|
||||
try {
|
||||
await ref.read(authRepositoryProvider).resetPassword(
|
||||
phone: phone,
|
||||
code: code,
|
||||
password: password,
|
||||
);
|
||||
await ref
|
||||
.read(authRepositoryProvider)
|
||||
.resetPassword(phone: phone, code: code, password: password);
|
||||
state = state.copyWith(isLoading: false);
|
||||
return true;
|
||||
} catch (e) {
|
||||
@@ -134,15 +132,11 @@ class AuthController extends Notifier<AuthState> {
|
||||
|
||||
/// 登出。
|
||||
///
|
||||
/// 除清除令牌与登录态外,还需失效当前账号的已绑定设备列表及由其推导的
|
||||
/// 选中设备 SN 等 Provider,否则切换账号登录后仍会读到上一账号缓存的设备/
|
||||
/// SN 数据(`myDevicesProvider` / `selectedDeviceSnProvider` 等持有旧值)。
|
||||
/// 会话版本变化后,应用根节点统一销毁当前账号的 ProviderScope。
|
||||
void logout() {
|
||||
_countdownTimer?.cancel();
|
||||
TokenStorage.clear();
|
||||
TokenStorage.clear().catchError((Object _) {});
|
||||
state = const AuthState();
|
||||
// 失效当前账号相关的设备与选中 SN 缓存,避免下一账号登录后沿用旧 SN。
|
||||
ref.invalidate(myDevicesProvider);
|
||||
}
|
||||
|
||||
Future<bool> _run(Future<LoginResult> Function() action) async {
|
||||
@@ -180,9 +174,9 @@ class AuthController extends Notifier<AuthState> {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// 认证控制器 Provider(会话级 keepAlive 在 build 内通过 ref.keepAlive 实现)。
|
||||
final authControllerProvider =
|
||||
NotifierProvider<AuthController, AuthState>(AuthController.new);
|
||||
final authControllerProvider = NotifierProvider<AuthController, AuthState>(
|
||||
AuthController.new,
|
||||
);
|
||||
Reference in new issue
Block a user