mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-12 02:57:22 +00:00
@@ -14,6 +14,7 @@ import 'platform_model.dart';
|
||||
class UserModel {
|
||||
final RxString userName = ''.obs;
|
||||
final RxBool isAdmin = false.obs;
|
||||
final RxBool fromServer = false.obs;
|
||||
WeakReference<FFI> parent;
|
||||
|
||||
UserModel(this.parent);
|
||||
@@ -48,7 +49,7 @@ class UserModel {
|
||||
}
|
||||
|
||||
final user = UserPayload.fromJson(data);
|
||||
await _parseAndUpdateUser(user);
|
||||
_parseAndUpdateUser(user);
|
||||
} catch (e) {
|
||||
print('Failed to refreshCurrentUser: $e');
|
||||
} finally {
|
||||
@@ -56,6 +57,22 @@ class UserModel {
|
||||
}
|
||||
}
|
||||
|
||||
static Map<String, dynamic>? getLocalUserInfo() {
|
||||
try {
|
||||
return json.decode(bind.mainGetLocalOption(key: 'user_info'));
|
||||
} catch (e) {
|
||||
print('Failed to get local user info: $e');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
_updateLocalUserInfo() {
|
||||
final userInfo = getLocalUserInfo();
|
||||
if (userInfo != null) {
|
||||
userName.value = userInfo['name'];
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> reset() async {
|
||||
await bind.mainSetLocalOption(key: 'access_token', value: '');
|
||||
await gFFI.abModel.reset();
|
||||
@@ -64,9 +81,10 @@ class UserModel {
|
||||
gFFI.peerTabModel.check_dynamic_tabs();
|
||||
}
|
||||
|
||||
Future<void> _parseAndUpdateUser(UserPayload user) async {
|
||||
_parseAndUpdateUser(UserPayload user) {
|
||||
userName.value = user.name;
|
||||
isAdmin.value = user.isAdmin;
|
||||
fromServer.value = true;
|
||||
}
|
||||
|
||||
Future<void> _updateOtherModels() async {
|
||||
@@ -110,11 +128,14 @@ class UserModel {
|
||||
print("login: jsonDecode resp body failed: ${e.toString()}");
|
||||
rethrow;
|
||||
}
|
||||
|
||||
if (resp.statusCode != 200) {
|
||||
throw RequestException(resp.statusCode, body['error'] ?? '');
|
||||
}
|
||||
|
||||
return getLoginResponseFromAuthBody(body);
|
||||
}
|
||||
|
||||
LoginResponse getLoginResponseFromAuthBody(Map<String, dynamic> body) {
|
||||
final LoginResponse loginResponse;
|
||||
try {
|
||||
loginResponse = LoginResponse.fromJson(body);
|
||||
@@ -124,7 +145,7 @@ class UserModel {
|
||||
}
|
||||
|
||||
if (loginResponse.user != null) {
|
||||
await _parseAndUpdateUser(loginResponse.user!);
|
||||
_parseAndUpdateUser(loginResponse.user!);
|
||||
}
|
||||
|
||||
return loginResponse;
|
||||
|
||||
Reference in New Issue
Block a user