Merge pull request from dignow/refact/login_dialog

Immediately show the login dialog
This commit is contained in:
RustDesk 2023-07-01 10:53:26 +08:00 committed by GitHub
commit 849ae9e55f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 48 deletions
flutter/lib
common/widgets
models

@ -378,7 +378,10 @@ Future<bool?> loginDialog() async {
var isInProgress = false; var isInProgress = false;
final RxString curOP = ''.obs; final RxString curOP = ''.obs;
final loginOptions = await UserModel.queryLoginOptions(); final loginOptions = [].obs;
Future.delayed(Duration.zero, () async {
loginOptions.value = await UserModel.queryLoginOptions();
});
final res = await gFFI.dialogManager.show<bool>((setState, close, context) { final res = await gFFI.dialogManager.show<bool>((setState, close, context) {
username.addListener(() { username.addListener(() {
@ -451,12 +454,12 @@ Future<bool?> loginDialog() async {
setState(() => isInProgress = false); setState(() => isInProgress = false);
} }
thirdAuthWidget() => Obx(() {
final oidcOptions = loginOptions final oidcOptions = loginOptions
.where((opt) => opt.startsWith(kAuthReqTypeOidc)) .where((opt) => opt.startsWith(kAuthReqTypeOidc))
.map((opt) => opt.substring(kAuthReqTypeOidc.length)) .map((opt) => opt.substring(kAuthReqTypeOidc.length))
.toList(); .toList();
return Offstage(
thirdAuthWidget() => Offstage(
offstage: oidcOptions.isEmpty, offstage: oidcOptions.isEmpty,
child: Column( child: Column(
children: [ children: [
@ -485,7 +488,8 @@ Future<bool?> loginDialog() async {
// access_token is already stored in the rust side. // access_token is already stored in the rust side.
gFFI.userModel.getLoginResponseFromAuthBody(authBody); gFFI.userModel.getLoginResponseFromAuthBody(authBody);
} catch (e) { } catch (e) {
debugPrint('Failed too parse oidc login body: "$authBody"'); debugPrint(
'Failed to parse oidc login body: "$authBody"');
} }
close(true); close(true);
}, },
@ -493,6 +497,7 @@ Future<bool?> loginDialog() async {
], ],
), ),
); );
});
return CustomAlertDialog( return CustomAlertDialog(
title: Text(translate('Login')), title: Text(translate('Login')),

@ -10,7 +10,7 @@ import '../common.dart';
import 'model.dart'; import 'model.dart';
import 'platform_model.dart'; import 'platform_model.dart';
bool refresing_user = false; bool refreshingUser = false;
class UserModel { class UserModel {
final RxString userName = ''.obs; final RxString userName = ''.obs;
@ -31,16 +31,16 @@ class UserModel {
'id': await bind.mainGetMyId(), 'id': await bind.mainGetMyId(),
'uuid': await bind.mainGetUuid() 'uuid': await bind.mainGetUuid()
}; };
if (refresing_user) return; if (refreshingUser) return;
try { try {
refresing_user = true; refreshingUser = true;
final response = await http.post(Uri.parse('$url/api/currentUser'), final response = await http.post(Uri.parse('$url/api/currentUser'),
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Authorization': 'Bearer $token' 'Authorization': 'Bearer $token'
}, },
body: json.encode(body)); body: json.encode(body));
refresing_user = false; refreshingUser = false;
final status = response.statusCode; final status = response.statusCode;
if (status == 401 || status == 400) { if (status == 401 || status == 400) {
reset(); reset();
@ -57,7 +57,7 @@ class UserModel {
} catch (e) { } catch (e) {
debugPrint('Failed to refreshCurrentUser: $e'); debugPrint('Failed to refreshCurrentUser: $e');
} finally { } finally {
refresing_user = false; refreshingUser = false;
await updateOtherModels(); await updateOtherModels();
} }
} }