mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-13 03:28:03 +00:00
Refact/verification code input check (#6924)
* Refact, login verification code, input check Signed-off-by: fufesou <shuanglongchen@yeah.net> * Refact, settings, enable 2fa, dialog input Signed-off-by: fufesou <shuanglongchen@yeah.net> * Refact. Connect, 2fa code, input check Signed-off-by: fufesou <shuanglongchen@yeah.net> * refact, 2Fa text field, input formatter, only digits Signed-off-by: fufesou <shuanglongchen@yeah.net> * refact, error message Signed-off-by: fufesou <shuanglongchen@yeah.net> --------- Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
@@ -615,23 +615,11 @@ Future<bool?> verificationCodeDialog(
|
||||
var autoLogin = true;
|
||||
var isInProgress = false;
|
||||
String? errorText;
|
||||
String preCode = '';
|
||||
|
||||
final code = TextEditingController();
|
||||
final focusNode = FocusNode()..requestFocus();
|
||||
Timer(Duration(milliseconds: 100), () => focusNode..requestFocus());
|
||||
|
||||
final res = await gFFI.dialogManager.show<bool>((setState, close, context) {
|
||||
bool validate() {
|
||||
return code.text.length >= 6;
|
||||
}
|
||||
|
||||
void onVerify() async {
|
||||
if (!validate()) {
|
||||
setState(
|
||||
() => errorText = translate('Too short, at least 6 characters.'));
|
||||
return;
|
||||
}
|
||||
setState(() => isInProgress = true);
|
||||
|
||||
try {
|
||||
@@ -666,18 +654,21 @@ Future<bool?> verificationCodeDialog(
|
||||
setState(() => isInProgress = false);
|
||||
}
|
||||
|
||||
code.addListener(() {
|
||||
if (errorText != null) {
|
||||
setState(() => errorText = null);
|
||||
}
|
||||
if (preCode.length != 6 && code.text.length == 6) {
|
||||
onVerify();
|
||||
}
|
||||
if (!isEmailVerification && preCode.length != 10 && code.text.length == 10) {
|
||||
onVerify();
|
||||
}
|
||||
preCode = code.text;
|
||||
});
|
||||
final codeField = isEmailVerification
|
||||
? DialogEmailCodeField(
|
||||
controller: code,
|
||||
errorText: errorText,
|
||||
readyCallback: onVerify,
|
||||
onChanged: () => errorText = null,
|
||||
)
|
||||
: Dialog2FaField(
|
||||
controller: code,
|
||||
errorText: errorText,
|
||||
readyCallback: onVerify,
|
||||
onChanged: () => errorText = null,
|
||||
);
|
||||
|
||||
getOnSubmit() => codeField.isReady ? onVerify : null;
|
||||
|
||||
return CustomAlertDialog(
|
||||
title: Text(translate("Verification code")),
|
||||
@@ -693,15 +684,7 @@ Future<bool?> verificationCodeDialog(
|
||||
controller: TextEditingController(text: user?.email),
|
||||
)),
|
||||
isEmailVerification ? const SizedBox(height: 8) : const Offstage(),
|
||||
DialogTextField(
|
||||
title:
|
||||
'${translate(isEmailVerification ? "Verification code" : "2FA code")}:',
|
||||
controller: code,
|
||||
errorText: errorText,
|
||||
focusNode: focusNode,
|
||||
helperText: translate(
|
||||
isEmailVerification ? 'verification_tip' : '2fa_tip'),
|
||||
),
|
||||
codeField,
|
||||
/*
|
||||
CheckboxListTile(
|
||||
contentPadding: const EdgeInsets.all(0),
|
||||
@@ -722,10 +705,10 @@ Future<bool?> verificationCodeDialog(
|
||||
],
|
||||
),
|
||||
onCancel: close,
|
||||
onSubmit: onVerify,
|
||||
onSubmit: getOnSubmit(),
|
||||
actions: [
|
||||
dialogButton("Cancel", onPressed: close, isOutline: true),
|
||||
dialogButton("Verify", onPressed: onVerify),
|
||||
dialogButton("Verify", onPressed: getOnSubmit()),
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user