Merge pull request #4705 from 21pages/email
sciter email login, add device info
This commit is contained in:
commit
c4058ae210
@ -592,7 +592,7 @@ pub fn main_get_default_sound_input() -> Option<String> {
|
||||
}
|
||||
|
||||
pub fn main_get_hostname() -> SyncReturn<String> {
|
||||
SyncReturn(crate::common::hostname())
|
||||
SyncReturn(get_hostname())
|
||||
}
|
||||
|
||||
pub fn main_change_id(new_id: String) {
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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'), <div .form .set-password>
|
||||
<div><span>{translate('Email')}:</span><span>{emailHint}</span></div>
|
||||
<div><span>{translate('Verification code')}:</span><input|text name="verification_code" .outline-focus /></div>
|
||||
<div style="font-size:0.9em; margin-bottom:1em;">{translate('verification_tip')}</div>
|
||||
</div>, "",
|
||||
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()
|
||||
};
|
||||
}
|
@ -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")))]
|
||||
|
Loading…
Reference in New Issue
Block a user