mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-12 11:06:57 +00:00
refactor user login:
1. opt request json type. 2. desktop and mobile use same loginDialog. 3. opt loginDialog UI style. 4. opt login request Exception catch.
This commit is contained in:
@@ -1,12 +1,22 @@
|
||||
import 'package:flutter_hbb/models/peer_model.dart';
|
||||
|
||||
class HttpType {
|
||||
static const kAuthReqTypeAccount = "account";
|
||||
static const kAuthReqTypeMobile = "mobile";
|
||||
static const kAuthReqTypeSMSCode = "sms_code";
|
||||
static const kAuthReqTypeEmailCode = "email_code";
|
||||
|
||||
static const kAuthResTypeToken = "access_token";
|
||||
static const kAuthResTypeEmailCheck = "email_check";
|
||||
}
|
||||
|
||||
class UserPayload {
|
||||
String name = '';
|
||||
String email = '';
|
||||
String note = '';
|
||||
int? status;
|
||||
String grp = '';
|
||||
bool is_admin = false;
|
||||
bool isAdmin = false;
|
||||
|
||||
UserPayload.fromJson(Map<String, dynamic> json)
|
||||
: name = json['name'] ?? '',
|
||||
@@ -14,7 +24,7 @@ class UserPayload {
|
||||
note = json['note'] ?? '',
|
||||
status = json['status'],
|
||||
grp = json['grp'] ?? '',
|
||||
is_admin = json['is_admin'] == true;
|
||||
isAdmin = json['is_admin'] == true;
|
||||
}
|
||||
|
||||
class PeerPayload {
|
||||
@@ -37,3 +47,81 @@ class PeerPayload {
|
||||
return Peer.fromJson({"id": p.id});
|
||||
}
|
||||
}
|
||||
|
||||
class LoginRequest {
|
||||
String? username;
|
||||
String? password;
|
||||
String? id;
|
||||
String? uuid;
|
||||
bool? autoLogin;
|
||||
String? type;
|
||||
String? verificationCode;
|
||||
String? deviceInfo;
|
||||
|
||||
LoginRequest(
|
||||
{this.username,
|
||||
this.password,
|
||||
this.id,
|
||||
this.uuid,
|
||||
this.autoLogin,
|
||||
this.type,
|
||||
this.verificationCode,
|
||||
this.deviceInfo});
|
||||
|
||||
LoginRequest.fromJson(Map<String, dynamic> json) {
|
||||
username = json['username'];
|
||||
password = json['password'];
|
||||
id = json['id'];
|
||||
uuid = json['uuid'];
|
||||
autoLogin = json['autoLogin'];
|
||||
type = json['type'];
|
||||
verificationCode = json['verificationCode'];
|
||||
deviceInfo = json['deviceInfo'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data['username'] = username ?? '';
|
||||
data['password'] = password ?? '';
|
||||
data['id'] = id ?? '';
|
||||
data['uuid'] = uuid ?? '';
|
||||
data['autoLogin'] = autoLogin ?? '';
|
||||
data['type'] = type ?? '';
|
||||
data['verificationCode'] = verificationCode ?? '';
|
||||
data['deviceInfo'] = deviceInfo ?? '';
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class LoginResponse {
|
||||
String? access_token;
|
||||
String? type;
|
||||
UserPayload? user;
|
||||
|
||||
LoginResponse({this.access_token, this.type, this.user});
|
||||
|
||||
LoginResponse.fromJson(Map<String, dynamic> json) {
|
||||
access_token = json['access_token'];
|
||||
type = json['type'];
|
||||
print("user: ${json['user']}");
|
||||
print("user id: ${json['user']['id']}");
|
||||
print("user name: ${json['user']['name']}");
|
||||
print("user email: ${json['user']['id']}");
|
||||
print("user note: ${json['user']['note']}");
|
||||
print("user status: ${json['user']['status']}");
|
||||
print("user grp: ${json['user']['grp']}");
|
||||
print("user is_admin: ${json['user']['is_admin']}");
|
||||
user = json['user'] != null ? UserPayload.fromJson(json['user']) : null;
|
||||
}
|
||||
}
|
||||
|
||||
class RequestException implements Exception {
|
||||
int statusCode;
|
||||
String cause;
|
||||
RequestException(this.statusCode, this.cause);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "RequestException, statusCode: $statusCode, error: $cause";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ import '../../desktop/widgets/material_mod_popup_menu.dart' as mod_menu;
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../common.dart';
|
||||
import '../../desktop/pages/desktop_home_page.dart';
|
||||
import '../../mobile/pages/settings_page.dart';
|
||||
|
||||
class AddressBook extends StatefulWidget {
|
||||
final EdgeInsets? menuPadding;
|
||||
@@ -41,21 +39,12 @@ class _AddressBookState extends State<AddressBook> {
|
||||
}
|
||||
});
|
||||
|
||||
handleLogin() {
|
||||
// TODO refactor login dialog for desktop and mobile
|
||||
if (isDesktop) {
|
||||
loginDialog();
|
||||
} else {
|
||||
showLogin(gFFI.dialogManager);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Widget> buildBody(BuildContext context) async {
|
||||
return Obx(() {
|
||||
if (gFFI.userModel.userName.value.isEmpty) {
|
||||
return Center(
|
||||
child: InkWell(
|
||||
onTap: handleLogin,
|
||||
onTap: loginDialog,
|
||||
child: Text(
|
||||
translate("Login"),
|
||||
style: const TextStyle(decoration: TextDecoration.underline),
|
||||
|
||||
Reference in New Issue
Block a user