Merge pull request #2978 from Heap-Hop/master
feat: add device info in LoginRequest
This commit is contained in:
commit
b83b0e79de
@ -1,5 +1,9 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter_hbb/models/peer_model.dart';
|
import 'package:flutter_hbb/models/peer_model.dart';
|
||||||
|
|
||||||
|
import '../../models/platform_model.dart';
|
||||||
|
|
||||||
class HttpType {
|
class HttpType {
|
||||||
static const kAuthReqTypeAccount = "account";
|
static const kAuthReqTypeAccount = "account";
|
||||||
static const kAuthReqTypeMobile = "mobile";
|
static const kAuthReqTypeMobile = "mobile";
|
||||||
@ -48,6 +52,16 @@ class PeerPayload {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DeviceInfo {
|
||||||
|
static Map<String, dynamic> toJson() {
|
||||||
|
final Map<String, dynamic> data = <String, dynamic>{};
|
||||||
|
data['os'] = Platform.operatingSystem;
|
||||||
|
data['type'] = "client";
|
||||||
|
data['name'] = bind.mainGetHostname();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class LoginRequest {
|
class LoginRequest {
|
||||||
String? username;
|
String? username;
|
||||||
String? password;
|
String? password;
|
||||||
@ -56,7 +70,7 @@ class LoginRequest {
|
|||||||
bool? autoLogin;
|
bool? autoLogin;
|
||||||
String? type;
|
String? type;
|
||||||
String? verificationCode;
|
String? verificationCode;
|
||||||
String? deviceInfo;
|
Map<String, dynamic> deviceInfo = DeviceInfo.toJson();
|
||||||
|
|
||||||
LoginRequest(
|
LoginRequest(
|
||||||
{this.username,
|
{this.username,
|
||||||
@ -65,19 +79,7 @@ class LoginRequest {
|
|||||||
this.uuid,
|
this.uuid,
|
||||||
this.autoLogin,
|
this.autoLogin,
|
||||||
this.type,
|
this.type,
|
||||||
this.verificationCode,
|
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() {
|
Map<String, dynamic> toJson() {
|
||||||
final Map<String, dynamic> data = <String, dynamic>{};
|
final Map<String, dynamic> data = <String, dynamic>{};
|
||||||
@ -88,7 +90,7 @@ class LoginRequest {
|
|||||||
data['autoLogin'] = autoLogin ?? '';
|
data['autoLogin'] = autoLogin ?? '';
|
||||||
data['type'] = type ?? '';
|
data['type'] = type ?? '';
|
||||||
data['verificationCode'] = verificationCode ?? '';
|
data['verificationCode'] = verificationCode ?? '';
|
||||||
data['deviceInfo'] = deviceInfo ?? '';
|
data['deviceInfo'] = deviceInfo;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,13 +80,15 @@ class UserModel {
|
|||||||
final tag = gFFI.dialogManager.showLoading(translate('Waiting'));
|
final tag = gFFI.dialogManager.showLoading(translate('Waiting'));
|
||||||
try {
|
try {
|
||||||
final url = await bind.mainGetApiServer();
|
final url = await bind.mainGetApiServer();
|
||||||
|
final authHeaders = getHttpHeaders();
|
||||||
|
authHeaders['Content-Type'] = "application/json";
|
||||||
await http
|
await http
|
||||||
.post(Uri.parse('$url/api/logout'),
|
.post(Uri.parse('$url/api/logout'),
|
||||||
body: {
|
body: jsonEncode({
|
||||||
'id': await bind.mainGetMyId(),
|
'id': await bind.mainGetMyId(),
|
||||||
'uuid': await bind.mainGetUuid(),
|
'uuid': await bind.mainGetUuid(),
|
||||||
},
|
}),
|
||||||
headers: getHttpHeaders())
|
headers: authHeaders)
|
||||||
.timeout(Duration(seconds: 2));
|
.timeout(Duration(seconds: 2));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("request /api/logout failed: err=$e");
|
print("request /api/logout failed: err=$e");
|
||||||
|
@ -451,6 +451,7 @@ pub fn run_me<T: AsRef<std::ffi::OsStr>>(args: Vec<T>) -> std::io::Result<std::p
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn username() -> String {
|
pub fn username() -> String {
|
||||||
// fix bug of whoami
|
// fix bug of whoami
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
@ -459,6 +460,14 @@ pub fn username() -> String {
|
|||||||
return DEVICE_NAME.lock().unwrap().clone();
|
return DEVICE_NAME.lock().unwrap().clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn hostname() -> String {
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
|
return whoami::hostname();
|
||||||
|
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||||
|
return DEVICE_NAME.lock().unwrap().clone();
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn check_port<T: std::string::ToString>(host: T, port: i32) -> String {
|
pub fn check_port<T: std::string::ToString>(host: T, port: i32) -> String {
|
||||||
hbb_common::socket_client::check_port(host, port)
|
hbb_common::socket_client::check_port(host, port)
|
||||||
@ -581,9 +590,9 @@ pub fn get_api_server(api: String, custom: String) -> String {
|
|||||||
if !s0.is_empty() {
|
if !s0.is_empty() {
|
||||||
let s = crate::increase_port(&s0, -2);
|
let s = crate::increase_port(&s0, -2);
|
||||||
if s == s0 {
|
if s == s0 {
|
||||||
format!("http://{}:{}", s, config::RENDEZVOUS_PORT - 2);
|
return format!("http://{}:{}", s, config::RENDEZVOUS_PORT - 2);
|
||||||
} else {
|
} else {
|
||||||
format!("http://{}", s);
|
return format!("http://{}", s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"https://admin.rustdesk.com".to_owned()
|
"https://admin.rustdesk.com".to_owned()
|
||||||
|
@ -523,6 +523,10 @@ pub fn main_get_sound_inputs() -> Vec<String> {
|
|||||||
vec![String::from("")]
|
vec![String::from("")]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn main_get_hostname() -> SyncReturn<String> {
|
||||||
|
SyncReturn(crate::common::hostname())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn main_change_id(new_id: String) {
|
pub fn main_change_id(new_id: String) {
|
||||||
change_id(new_id)
|
change_id(new_id)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user