Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

Better 2fa verification support (#6782)

fufesou7e3a0c4ded92
diff --git a/flutter/lib/common/hbbs/hbbs.dart b/flutter/lib/common/hbbs/hbbs.dart
index 013ce8919..2bb5bc40b 100644
--- a/flutter/lib/common/hbbs/hbbs.dart
+++ b/flutter/lib/common/hbbs/hbbs.dart
@@ -11,9 +11,11 @@ class HttpType {
static const kAuthReqTypeMobile = "mobile";
static const kAuthReqTypeSMSCode = "sms_code";
static const kAuthReqTypeEmailCode = "email_code";
+ static const kAuthReqTypeTfaCode = "tfa_code";
static const kAuthResTypeToken = "access_token";
static const kAuthResTypeEmailCheck = "email_check";
+ static const kAuthResTypeTfaCheck = "tfa_check";
}
enum UserStatus { kDisabled, kNormal, kUnverified }
@@ -118,6 +120,7 @@ class LoginRequest {
bool? autoLogin;
String? type;
String? verificationCode;
+ String? tfaCode;
LoginRequest(
{this.username,
@@ -126,7 +129,8 @@ class LoginRequest {
this.uuid,
this.autoLogin,
this.type,
- this.verificationCode});
+ this.verificationCode,
+ this.tfaCode});
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
@@ -139,6 +143,7 @@ class LoginRequest {
if (verificationCode != null) {
data['verificationCode'] = verificationCode;
}
+ if (tfaCode != null) data['tfaCode'] = tfaCode;
Map<String, dynamic> deviceInfo = {};
try {
@@ -154,13 +159,15 @@ class LoginRequest {
class LoginResponse {
String? access_token;
String? type;
+ String? tfa_type;
UserPayload? user;
- LoginResponse({this.access_token, this.type, this.user});
+ LoginResponse({this.access_token, this.type, this.tfa_type, this.user});
LoginResponse.fromJson(Map<String, dynamic> json) {
access_token = json['access_token'];
type = json['type'];
+ tfa_type = json['tfa_type'];
user = json['user'] != null ? UserPayload.fromJson(json['user']) : null;
}
}
diff --git a/flutter/lib/common/widgets/login.dart b/flutter/lib/common/widgets/login.dart
index f45299f80..e189aaf54 100644
--- a/flutter/lib/common/widgets/login.dart
+++ b/flutter/lib/common/widgets/login.dart
@@ -427,6 +427,54 @@ Future<bool?> loginDialog() async {
close(false);
}
+ handleLoginResponse(LoginResponse resp, bool storeIfAccessToken,
+ void Function([dynamic])? close) async {
+ switch (resp.type) {
+ case HttpType.kAuthResTypeToken:
+ if (resp.access_token != null) {
+ if (storeIfAccessToken) {
+ await bind.mainSetLocalOption(
+ key: 'access_token', value: resp.access_token!);
+ await bind.mainSetLocalOption(
+ key: 'user_info', value: jsonEncode(resp.user ?? {}));
+ }
+ if (close != null) {
+ close(true);
+ }
+ return;
+ }
+ break;
+ case HttpType.kAuthResTypeEmailCheck:
+ bool? isEmailVerification;
+ if (resp.tfa_type == null ||
+ resp.tfa_type == HttpType.kAuthResTypeEmailCheck) {
+ isEmailVerification = true;
+ } else if (resp.tfa_type == HttpType.kAuthResTypeTfaCheck) {
+ isEmailVerification = false;
+ } else {
+ passwordMsg = "Failed, bad tfa type from server";
+ }
+ if (isEmailVerification != null) {
+ if (isMobile) {
+ if (close != null) close(false);
+ verificationCodeDialog(resp.user, isEmailVerification);
+ } else {
+ setState(() => isInProgress = false);
+ final res =
+ await verificationCodeDialog(resp.user, isEmailVerification);
+ if (res == true) {
+ if (close != null) close(false);
+ return;
+ }
+ }
+ }
+ break;
+ default:
+ passwordMsg = "Failed, bad response from server";
+ break;
+ }
+ }
+
onLogin() async {
// validate
if (username.text.isEmpty) {
@@ -447,35 +495,7 @@ Future<bool?> loginDialog() async {
uuid: await bind.mainGetUuid(),
autoLogin: true,
type: HttpType.kAuthReqTypeAccount));
-
- switch (resp.type) {
- case HttpType.kAuthResTypeToken:
- if (resp.access_token != null) {
- await bind.mainSetLocalOption(
- key: 'access_token', value: resp.access_token!);
- await bind.mainSetLocalOption(
- key: 'user_info', value: jsonEncode(resp.user ?? {}));
- close(true);
- return;
- }
- break;
- case HttpType.kAuthResTypeEmailCheck:
- if (isMobile) {
- close(true);
- verificationCodeDialog(resp.user);
- } else {
- setState(() => isInProgress = false);
- final res = await verificationCodeDialog(resp.user);
- if (res == true) {
- close(true);
- return;
- }
- }
- break;
- default:
- passwordMsg = "Failed, bad response from server";
- break;
- }
+ await handleLoginResponse(resp, true, close);
} on RequestException catch (err) {
passwordMsg = translate(err.cause);
} catch (err) {
@@ -506,15 +526,21 @@ Future<bool?> loginDialog() async {
.map((e) => ConfigOP(op: e['name'], icon: e['icon']))
.toList(),
curOP: curOP,
- cbLogin: (Map<String, dynamic> authBody) {
+ cbLogin: (Map<String, dynamic> authBody) async {
+ LoginResponse? resp;
try {
// access_token is already stored in the rust side.
- gFFI.userModel.getLoginResponseFromAuthBody(authBody);
+ resp =
+ gFFI.userModel.getLoginResponseFromAuthBody(authBody);
} catch (e) {
debugPrint(
'Failed to parse oidc login body: "$authBody"');
}
close(true);
+
+ if (resp != null) {
+ handleLoginResponse(resp, false, null);
+ }
},
),
],
@@ -583,7 +609,8 @@ Future<bool?> loginDialog() async {
return res;
}
-Future<bool?> verificationCodeDialog(UserPayload? user) async {
+Future<bool?> verificationCodeDialog(
+ UserPayload? user, bool isEmailVerification) async {
var autoLogin = true;
var isInProgress = false;
String? errorText;
@@ -614,6 +641,7 @@ Future<bool?> verificationCodeDialog(UserPayload? user) async {
try {
final resp = await gFFI.userModel.login(LoginRequest(
verificationCode: code.text,
+ tfaCode: isEmailVerification ? null : code.text,
username: user?.name,
id: await bind.mainGetMyId(),
uuid: await bind.mainGetUuid(),
@@ -648,20 +676,22 @@ Future<bool?> verificationCodeDialog(UserPayload? user) async {
content: Column(
children: [
Offstage(
- offstage: user?.email == null,
+ offstage: !isEmailVerification || user?.email == null,
child: TextField(
decoration: InputDecoration(
labelText: "Email", prefixIcon: Icon(Icons.email)),
readOnly: true,
controller: TextEditingController(text: user?.email),
)),
- const SizedBox(height: 8),
+ isEmailVerification ? const SizedBox(height: 8) : const Offstage(),
DialogTextField(
- title: '${translate("Verification code")}:',
+ title:
+ '${translate(isEmailVerification ? "Verification code" : "2FA code")}:',
controller: code,
errorText: errorText,
focusNode: focusNode,
- helperText: translate('verification_tip'),
+ helperText: translate(
+ isEmailVerification ? 'verification_tip' : '2fa_tip'),
),
/*
CheckboxListTile(
diff --git a/src/hbbs_http/account.rs b/src/hbbs_http/account.rs
index e76dda76c..7e35905b2 100644
--- a/src/hbbs_http/account.rs
+++ b/src/hbbs_http/account.rs
@@ -95,6 +95,8 @@ pub struct UserPayload {
pub struct AuthBody {
pub access_token: String,
pub r#type: String,
+ #[serde(default)]
+ pub tfa_type: String,
pub user: UserPayload,
}
@@ -238,15 +240,17 @@ impl OidcSession {
while OIDC_SESSION.read().unwrap().keep_querying && begin.elapsed() < query_timeout {
match Self::query(&api_server, &code_url.code, &id, &uuid) {
Ok(HbbHttpResponse::<_>::Data(auth_body)) => {
- if remember_me {
- LocalConfig::set_option(
- "access_token".to_owned(),
- auth_body.access_token.clone(),
- );
- LocalConfig::set_option(
- "user_info".to_owned(),
- serde_json::json!({ "name": auth_body.user.name, "status": auth_body.user.status }).to_string(),
- );
+ if auth_body.r#type == "access_token" {
+ if remember_me {
+ LocalConfig::set_option(
+ "access_token".to_owned(),
+ auth_body.access_token.clone(),
+ );
+ LocalConfig::set_option(
+ "user_info".to_owned(),
+ serde_json::json!({ "name": auth_body.user.name, "status": auth_body.user.status }).to_string(),
+ );
+ }
}
OIDC_SESSION
.write()
diff --git a/src/lang/ar.rs b/src/lang/ar.rs
index e09c94977..381750e81 100644
--- a/src/lang/ar.rs
+++ b/src/lang/ar.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/ca.rs b/src/lang/ca.rs
index ef2701f8b..b292de892 100644
--- a/src/lang/ca.rs
+++ b/src/lang/ca.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/cn.rs b/src/lang/cn.rs
index 4ac6bcde8..8fe7c4c69 100644
--- a/src/lang/cn.rs
+++ b/src/lang/cn.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", "用户提权后,不能显示多个显示器。若要控制多显示器,请安装后再试。"),
("Swap control-command key", "交换Control键和Command键"),
("swap-left-right-mouse", "交换鼠标左右键"),
+ ("2FA code", "2FA code"),
+ ("2fa_tip", "请输入授权 app 中的 2FA code"),
].iter().cloned().collect();
}
diff --git a/src/lang/cs.rs b/src/lang/cs.rs
index 2b820c865..52856062c 100644
--- a/src/lang/cs.rs
+++ b/src/lang/cs.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", "Snímání více displejů není podporováno v uživatelském režimu se zvýšenými oprávněními. Pokud chcete ovládat více displejů, zkuste to znovu po instalaci."),
("Swap control-command key", "Prohození klávesy control-command"),
("swap-left-right-mouse", "Prohodit levé a pravé tlačítko myši"),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/da.rs b/src/lang/da.rs
index af277f450..7414f6ef1 100644
--- a/src/lang/da.rs
+++ b/src/lang/da.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/de.rs b/src/lang/de.rs
index 6f40692bb..9596b5cf3 100644
--- a/src/lang/de.rs
+++ b/src/lang/de.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", "Das Erfassen mehrerer Bildschirme wird im erweiterten Benutzermodus nicht unterstützt. Bitte versuchen Sie es nach der Installation erneut, wenn Sie mehrere Bildschirme steuern möchten."),
("Swap control-command key", "Steuerungs- und Befehlstasten tauschen"),
("swap-left-right-mouse", "Linke und rechte Maustaste tauschen"),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/el.rs b/src/lang/el.rs
index 7a79b5edb..e32b93c31 100644
--- a/src/lang/el.rs
+++ b/src/lang/el.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/en.rs b/src/lang/en.rs
index a9a8c2618..b0ade15e4 100644
--- a/src/lang/en.rs
+++ b/src/lang/en.rs
@@ -210,5 +210,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("input_source_2_tip", "Input source 2"),
("capture_display_elevated_connections_tip", "Capturing multiple displays is not supported in the elevated user mode. Please try again after installation if you want to control multiple displays."),
("swap-left-right-mouse", "Swap left-right mouse button"),
+ ("2FA code", "2FA code"),
+ ("2fa_tip", "Please enter the your 2FA code in the authentication app."),
].iter().cloned().collect();
}
diff --git a/src/lang/eo.rs b/src/lang/eo.rs
index 44d6b146f..edd8b914f 100644
--- a/src/lang/eo.rs
+++ b/src/lang/eo.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/es.rs b/src/lang/es.rs
index e31af3c2c..9c112e0dd 100644
--- a/src/lang/es.rs
+++ b/src/lang/es.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", "La captura de múltiples pantallas en el modo de usaurio con privilegios elevados no está soportada. Por favor, inténtalo de nuevo tras la instalación si quieres controlar múltiples pantallas."),
("Swap control-command key", "Intercambiar teclas control-comando"),
("swap-left-right-mouse", "Intercambiar botones derecho-izquierdo del ratón"),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/et.rs b/src/lang/et.rs
index 21f25d4bf..cb300a356 100644
--- a/src/lang/et.rs
+++ b/src/lang/et.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", "Mitme ekraani jäädvustamine ei ole kõrgendatud kasutajarežiimis toetatud. Kui soovid juhtida mitut ekraani, palun proovi uuesti pärast paigaldamist."),
("Swap control-command key", ""),
("swap-left-right-mouse", "Vaheta vasak ja parem hiirenupp"),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/fa.rs b/src/lang/fa.rs
index 388c1491d..33e168ba8 100644
--- a/src/lang/fa.rs
+++ b/src/lang/fa.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/fr.rs b/src/lang/fr.rs
index c2b0654f9..b24cccf85 100644
--- a/src/lang/fr.rs
+++ b/src/lang/fr.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", "La capture de plusieurs écrans n'est pas prise en charge en mode utilisateur avec privilièges. Veuillez réessayer après l'installation si vous souhaitez contrôler plusieurs écrans."),
("Swap control-command key", "Échanger la touche de controle-commande"),
("swap-left-right-mouse", "Intervertir le bouton gauche et droit de la souris"),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/hu.rs b/src/lang/hu.rs
index 63d1d56b3..51e55128e 100644
--- a/src/lang/hu.rs
+++ b/src/lang/hu.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/id.rs b/src/lang/id.rs
index e20fdf05f..8881adc70 100644
--- a/src/lang/id.rs
+++ b/src/lang/id.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/it.rs b/src/lang/it.rs
index b285c28b3..80e4d8353 100644
--- a/src/lang/it.rs
+++ b/src/lang/it.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", "La cattura di più display non è supportata nella modalità utente con privilegi elevati. Se vuoi controllare più display riprova dopo l'installazione."),
("Swap control-command key", "Scambia tasto controllo-comando"),
("swap-left-right-mouse", "Scambia pulsante sinistro-destro mouse"),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/ja.rs b/src/lang/ja.rs
index 0bc9c42d3..de14c5e2f 100644
--- a/src/lang/ja.rs
+++ b/src/lang/ja.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/ko.rs b/src/lang/ko.rs
index dd93ca3f7..07b5dbade 100644
--- a/src/lang/ko.rs
+++ b/src/lang/ko.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", "권한 상승된 사용자 모드에서는 다중 디스플레이 캡처가 지원되지 않습니다. 다중 디스플레이를 제어하려면 설치 후 재시도하세요."),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/kz.rs b/src/lang/kz.rs
index 9571d23a1..afa2e3459 100644
--- a/src/lang/kz.rs
+++ b/src/lang/kz.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/lt.rs b/src/lang/lt.rs
index 0076be89f..f8474ac9e 100644
--- a/src/lang/lt.rs
+++ b/src/lang/lt.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/lv.rs b/src/lang/lv.rs
index 101a198a8..f103769ce 100644
--- a/src/lang/lv.rs
+++ b/src/lang/lv.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", "Vairāku displeju uzņemšana netiek atbalstīta paaugstinātā lietotāja režīmā. Lūdzu, mēģiniet vēlreiz pēc instalēšanas, ja vēlaties kontrolēt vairākus displejus."),
("Swap control-command key", "Apmainīt vadības un komandas taustiņu"),
("swap-left-right-mouse", "Apmainīt kreiso un labo peles pogu"),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/nb.rs b/src/lang/nb.rs
index edcc62c58..1bcae0702 100644
--- a/src/lang/nb.rs
+++ b/src/lang/nb.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/nl.rs b/src/lang/nl.rs
index 26e70e2b3..6a6cf89a8 100644
--- a/src/lang/nl.rs
+++ b/src/lang/nl.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", "Scannen van meerdere schermen wordt niet ondersteund in de bevoorrechte gebruikersmodus. Als je meerdere schermen wilt bedienen, probeer het dan opnieuw na de installatie."),
("Swap control-command key", "Wissel controle-commando toets"),
("swap-left-right-mouse", "wissel-links-rechts-muis"),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/pl.rs b/src/lang/pl.rs
index 7a5cd023d..9856b2abb 100644
--- a/src/lang/pl.rs
+++ b/src/lang/pl.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", "Przechwytywanie wielu ekranów nie jest obsługiwane w trybie użytkownika z podwyższonym poziomem uprawnień. Jeśli chcesz sterować wieloma wyświetlaczami, spróbuj ponownie po instalacji."),
("Swap control-command key", "Zamiana przycisków sterujących myszki"),
("swap-left-right-mouse", "Zamień przyciski myszki (lewy - prawy)"),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/pt_PT.rs b/src/lang/pt_PT.rs
index 23245cb11..4902b0218 100644
--- a/src/lang/pt_PT.rs
+++ b/src/lang/pt_PT.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/ptbr.rs b/src/lang/ptbr.rs
index 9ec9122cd..f021b6094 100644
--- a/src/lang/ptbr.rs
+++ b/src/lang/ptbr.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/ro.rs b/src/lang/ro.rs
index 153bdd2cd..dca2b854e 100644
--- a/src/lang/ro.rs
+++ b/src/lang/ro.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/ru.rs b/src/lang/ru.rs
index e6f6efb2e..6f478bc31 100644
--- a/src/lang/ru.rs
+++ b/src/lang/ru.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", "Захват экрана нескольких дисплеев не поддерживается в режиме повышенных прав. Повторите попытку после установки, если хотите управлять несколькими дисплеями."),
("Swap control-command key", "Поменять кнопки управления и команд"),
("swap-left-right-mouse", "Поменять левую и правую кнопки мыши"),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/sk.rs b/src/lang/sk.rs
index faf4e2a43..1bf47b015 100644
--- a/src/lang/sk.rs
+++ b/src/lang/sk.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", "Snímanie viacerých displejov nie je podporované v režime privilegovaného používateľa. Ak chcete ovládať viac displejov, skúste to po inštalácii znova."),
("Swap control-command key", "Vymeniť kláves ovládania a príkazu"),
("swap-left-right-mouse", "Prehodiť ľavé a pravé tlačidlo myši"),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/sl.rs b/src/lang/sl.rs
index 0607af020..757a70380 100755
--- a/src/lang/sl.rs
+++ b/src/lang/sl.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/sq.rs b/src/lang/sq.rs
index 8d59faf35..584408076 100644
--- a/src/lang/sq.rs
+++ b/src/lang/sq.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/sr.rs b/src/lang/sr.rs
index 7a9157cac..099e59c37 100644
--- a/src/lang/sr.rs
+++ b/src/lang/sr.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/sv.rs b/src/lang/sv.rs
index 2a06e8b10..cb5e41549 100644
--- a/src/lang/sv.rs
+++ b/src/lang/sv.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/template.rs b/src/lang/template.rs
index 6ab55c85a..60ae853b8 100644
--- a/src/lang/template.rs
+++ b/src/lang/template.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/th.rs b/src/lang/th.rs
index 15eec7219..afb812c11 100644
--- a/src/lang/th.rs
+++ b/src/lang/th.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/tr.rs b/src/lang/tr.rs
index 3be48a83b..f9c5d0304 100644
--- a/src/lang/tr.rs
+++ b/src/lang/tr.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/tw.rs b/src/lang/tw.rs
index 8bf85f7cb..fe6a65e53 100644
--- a/src/lang/tw.rs
+++ b/src/lang/tw.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/ua.rs b/src/lang/ua.rs
index edb4b0ef1..10ee99713 100644
--- a/src/lang/ua.rs
+++ b/src/lang/ua.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", "В режимі розширених прав захоплення декількох дисплеїв не підтримується. Якщо ви хочете керувати декількома дисплеями, будь ласка, спробуйте це після встановлення."),
("Swap control-command key", "Поміняти місцями клавіші Control та Command"),
("swap-left-right-mouse", "Поміняти місцями ліву та праву кнопки миші"),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/lang/vn.rs b/src/lang/vn.rs
index d16b18224..2c2751a8a 100644
--- a/src/lang/vn.rs
+++ b/src/lang/vn.rs
@@ -578,5 +578,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("capture_display_elevated_connections_tip", ""),
("Swap control-command key", ""),
("swap-left-right-mouse", ""),
+ ("2FA code", ""),
+ ("2fa_tip", ""),
].iter().cloned().collect();
}
diff --git a/src/ui/index.tis b/src/ui/index.tis
index 5def2d32b..13c8141c3 100644
--- a/src/ui/index.tis
+++ b/src/ui/index.tis
@@ -1223,7 +1223,7 @@ function login() {
if (data.type == 'email_check') {
abLoading = false;
show_progress(-1);
- on_email_check(data);
+ on_2fa_check(data);
return;
}
handler.set_local_option("access_token", data.access_token);
@@ -1241,12 +1241,14 @@ function login() {
});
}
-function on_email_check(last_msg) {
+function on_2fa_check(last_msg) {
+ var isEmailCheck = !last_msg.tfa_type || last_msg.tfa_type == 'email_check';
+
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>
+ msgbox("custom-2fa-verification-code", translate('Verification code'), <div .form .set-password>
+ { isEmailCheck && <div><span>{translate('Email')}:</span><span>{emailHint}</span></div> }
+ <div><span>{translate(isEmailCheck ? 'Verification code' : '2FA code')}:</span><input|text name="verification_code" .outline-focus /></div>
+ <div style="font-size:0.9em; margin-bottom:1em;">{translate(isEmailCheck ? 'verification_tip' : '2fa_tip')}</div>
</div>, "",
function(res=null, show_progress) {
if (!res) return;
@@ -1258,7 +1260,8 @@ function on_email_check(last_msg) {
}
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', autoLogin: true, verificationCode: code, deviceInfo: getDeviceInfo()},
+ const loginData = {username: last_msg.user.name, id: my_id, uuid: handler.get_uuid(), type: 'email_code', verificationCode: code, tfaCode: isEmailCheck ? '' : code, deviceInfo: getDeviceInfo()};
+ httpRequest(url + "/api/login", #post, loginData,
function(data) {
if (data.error) {
abLoading = false;