diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index 8cf0893ba..b3c011c2b 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -592,7 +592,7 @@ pub fn main_get_default_sound_input() -> Option { } pub fn main_get_hostname() -> SyncReturn { - SyncReturn(crate::common::hostname()) + SyncReturn(get_hostname()) } pub fn main_change_id(new_id: String) { diff --git a/src/ui.rs b/src/ui.rs index c0bd988c9..94ae30cf6 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -585,6 +585,10 @@ impl UI { fn handle_relay_id(&self, id: String) -> String { handle_relay_id(id) } + + fn get_hostname(&self) -> String { + get_hostname() + } } impl sciter::EventHandler for UI { @@ -669,6 +673,7 @@ impl sciter::EventHandler for UI { fn get_langs(); fn default_video_save_directory(); fn handle_relay_id(String); + fn get_hostname(); } } diff --git a/src/ui/index.tis b/src/ui/index.tis index 669cc1b29..d420344cd 100644 --- a/src/ui/index.tis +++ b/src/ui/index.tis @@ -1195,13 +1195,19 @@ function login() { } abLoading = true; var url = handler.get_api_server(); - httpRequest(url + "/api/login", #post, {username: name, password: pass, id: my_id, uuid: handler.get_uuid(), type: 'account'}, function(data) { + httpRequest(url + "/api/login", #post, {username: name, password: pass, id: my_id, uuid: handler.get_uuid(), type: 'account', deviceInfo: getDeviceInfo()}, function(data) { if (data.error) { abLoading = false; var err = translate(data.error); show_progress(false, err); return; } + if (data.type == 'email_check') { + abLoading = false; + show_progress(-1); + on_email_check(data); + return; + } handler.set_local_option("access_token", data.access_token); handler.set_local_option("user_info", JSON.stringify(data.user)); show_progress(-1); @@ -1217,6 +1223,48 @@ function login() { }); } +function on_email_check(last_msg) { + var emailHint = last_msg.user.email; + msgbox("custom-email-verification-code", translate('Verification code'),
+
{translate('Email')}:{emailHint}
+
{translate('Verification code')}:
+
{translate('verification_tip')}
+
, "", + function(res=null, show_progress) { + if (!res) return; + show_progress(); + var code = (res.verification_code || '').trim(); + if (!code || code.length < 6) { + show_progress(false, translate("Too short, at least 6 characters.")); + return " "; + } + abLoading = true; + var url = handler.get_api_server(); + httpRequest(url + "/api/login", #post, {username: last_msg.user.name, id: my_id, uuid: handler.get_uuid(), type: 'email_code', trustThisDevice: false, verificationCode: code, deviceInfo: getDeviceInfo()}, + function(data) { + if (data.type != 'access_token') { + abLoading = false; + show_progress(false, "Failed, bad response from server."); + return; + } + handler.set_local_option("access_token", data.access_token); + handler.set_local_option("user_info", JSON.stringify(data.user)); + show_progress(-1); + myIdMenu.update(); + getAb(); + }, + function(err, status) { + abLoading = false; + err = translate(err); + if (url.indexOf('rustdesk') < 0) err = url + ', ' + err; + show_progress(false, err); + } + ); + return " "; + } + ); +} + function reset_token() { handler.set_local_option("access_token", ""); handler.set_local_option("user_info", ""); @@ -1261,3 +1309,20 @@ function refreshCurrentUser() { function getHttpHeaders() { return "Authorization: Bearer " + handler.get_local_option("access_token"); } + +function getDeviceInfo() { + var os; + if (is_win) { + os = 'windows'; + } else if (is_linux) { + os = 'linux'; + } else if (is_osx) { + os = 'macos'; + } + + return { + os: os, + type: 'client', + name: handler.get_hostname() + }; +} \ No newline at end of file diff --git a/src/ui_interface.rs b/src/ui_interface.rs index a901fd4e6..e298e1167 100644 --- a/src/ui_interface.rs +++ b/src/ui_interface.rs @@ -848,6 +848,10 @@ pub fn get_fingerprint() -> String { return ipc::get_fingerprint(); } +pub fn get_hostname() -> String { + crate::common::hostname() +} + // notice: avoiding create ipc connection repeatedly, // because windows named pipe has serious memory leak issue. #[cfg(not(any(target_os = "android", target_os = "ios")))]