sciter email login, add device info

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2023-06-20 10:29:27 +08:00
parent af309096c9
commit 42798870c1
4 changed files with 76 additions and 2 deletions

View File

@@ -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()
};
}