Skip to content

Commit a42df9a

Browse files
authored
Refact, verification login with secret (rustdesk#6943)
Signed-off-by: fufesou <shuanglongchen@yeah.net>
1 parent 48102e9 commit a42df9a

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

flutter/lib/common/hbbs/hbbs.dart

+8-2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class LoginRequest {
121121
String? type;
122122
String? verificationCode;
123123
String? tfaCode;
124+
String? secret;
124125

125126
LoginRequest(
126127
{this.username,
@@ -130,7 +131,8 @@ class LoginRequest {
130131
this.autoLogin,
131132
this.type,
132133
this.verificationCode,
133-
this.tfaCode});
134+
this.tfaCode,
135+
this.secret});
134136

135137
Map<String, dynamic> toJson() {
136138
final Map<String, dynamic> data = <String, dynamic>{};
@@ -144,6 +146,7 @@ class LoginRequest {
144146
data['verificationCode'] = verificationCode;
145147
}
146148
if (tfaCode != null) data['tfaCode'] = tfaCode;
149+
if (secret != null) data['secret'] = secret;
147150

148151
Map<String, dynamic> deviceInfo = {};
149152
try {
@@ -160,14 +163,17 @@ class LoginResponse {
160163
String? access_token;
161164
String? type;
162165
String? tfa_type;
166+
String? secret;
163167
UserPayload? user;
164168

165-
LoginResponse({this.access_token, this.type, this.tfa_type, this.user});
169+
LoginResponse(
170+
{this.access_token, this.type, this.tfa_type, this.secret, this.user});
166171

167172
LoginResponse.fromJson(Map<String, dynamic> json) {
168173
access_token = json['access_token'];
169174
type = json['type'];
170175
tfa_type = json['tfa_type'];
176+
secret = json['secret'];
171177
user = json['user'] != null ? UserPayload.fromJson(json['user']) : null;
172178
}
173179
}

flutter/lib/common/widgets/login.dart

+7-6
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,7 @@ class LoginWidgetUserPass extends StatelessWidget {
390390

391391
const kAuthReqTypeOidc = 'oidc/';
392392

393-
/// common login dialog for desktop
394-
/// call this directly
393+
// call this directly
395394
Future<bool?> loginDialog() async {
396395
var username =
397396
TextEditingController(text: UserModel.getLocalUserInfo()?['name'] ?? '');
@@ -457,11 +456,12 @@ Future<bool?> loginDialog() async {
457456
if (isEmailVerification != null) {
458457
if (isMobile) {
459458
if (close != null) close(false);
460-
verificationCodeDialog(resp.user, isEmailVerification);
459+
verificationCodeDialog(
460+
resp.user, resp.secret, isEmailVerification);
461461
} else {
462462
setState(() => isInProgress = false);
463-
final res =
464-
await verificationCodeDialog(resp.user, isEmailVerification);
463+
final res = await verificationCodeDialog(
464+
resp.user, resp.secret, isEmailVerification);
465465
if (res == true) {
466466
if (close != null) close(false);
467467
return;
@@ -611,7 +611,7 @@ Future<bool?> loginDialog() async {
611611
}
612612

613613
Future<bool?> verificationCodeDialog(
614-
UserPayload? user, bool isEmailVerification) async {
614+
UserPayload? user, String? secret, bool isEmailVerification) async {
615615
var autoLogin = true;
616616
var isInProgress = false;
617617
String? errorText;
@@ -626,6 +626,7 @@ Future<bool?> verificationCodeDialog(
626626
final resp = await gFFI.userModel.login(LoginRequest(
627627
verificationCode: code.text,
628628
tfaCode: isEmailVerification ? null : code.text,
629+
secret: secret,
629630
username: user?.name,
630631
id: await bind.mainGetMyId(),
631632
uuid: await bind.mainGetUuid(),

src/hbbs_http/account.rs

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ pub struct AuthBody {
9797
pub r#type: String,
9898
#[serde(default)]
9999
pub tfa_type: String,
100+
#[serde(default)]
101+
pub secret: String,
100102
pub user: UserPayload,
101103
}
102104

src/ui/index.tis

+13-3
Original file line numberDiff line numberDiff line change
@@ -1242,9 +1242,10 @@ function login() {
12421242
}
12431243

12441244
function on_2fa_check(last_msg) {
1245-
var isEmailCheck = !last_msg.tfa_type || last_msg.tfa_type == 'email_check';
1245+
const isEmailCheck = !last_msg.tfa_type || last_msg.tfa_type == 'email_check';
1246+
const secret = last_msg.secret;
1247+
const emailHint = last_msg.user.email;
12461248

1247-
var emailHint = last_msg.user.email;
12481249
msgbox("custom-2fa-verification-code", translate('Verification code'), <div .form .set-password>
12491250
{ isEmailCheck && <div><span>{translate('Email')}:</span><span>{emailHint}</span></div> }
12501251
<div><span>{translate(isEmailCheck ? 'Verification code' : '2FA code')}:</span><input|text name="verification_code" .outline-focus /></div>
@@ -1260,7 +1261,16 @@ function on_2fa_check(last_msg) {
12601261
}
12611262
abLoading = true;
12621263
var url = handler.get_api_server();
1263-
const loginData = {username: last_msg.user.name, id: my_id, uuid: handler.get_uuid(), type: 'email_code', verificationCode: code, tfaCode: isEmailCheck ? '' : code, deviceInfo: getDeviceInfo()};
1264+
const loginData = {
1265+
username: last_msg.user.name,
1266+
id: my_id,
1267+
uuid: handler.get_uuid(),
1268+
type: 'email_code',
1269+
verificationCode: code,
1270+
tfaCode: isEmailCheck ? '' : code,
1271+
secret: secret,
1272+
deviceInfo: getDeviceInfo()
1273+
};
12641274
httpRequest(url + "/api/login", #post, loginData,
12651275
function(data) {
12661276
if (data.error) {

0 commit comments

Comments
 (0)