commit
08cc772ff1
|
@ -27,6 +27,43 @@ class Code {
|
|||
this.generatedID,
|
||||
});
|
||||
|
||||
Code copyWith({
|
||||
String? account,
|
||||
String? issuer,
|
||||
int? digits,
|
||||
int? period,
|
||||
String? secret,
|
||||
Algorithm? algorithm,
|
||||
Type? type,
|
||||
}) {
|
||||
final String updateAccount = account ?? this.account;
|
||||
final String updateIssuer = issuer ?? this.issuer;
|
||||
final int updatedDigits = digits ?? this.digits;
|
||||
final int updatePeriod = period ?? this.period;
|
||||
final String updatedSecret = secret ?? this.secret;
|
||||
final Algorithm updatedAlgo = algorithm ?? this.algorithm;
|
||||
final Type updatedType = type ?? this.type;
|
||||
|
||||
return Code(
|
||||
updateAccount,
|
||||
updateIssuer,
|
||||
updatedDigits,
|
||||
updatePeriod,
|
||||
updatedSecret,
|
||||
updatedAlgo,
|
||||
updatedType,
|
||||
"otpauth://${updatedType.name}/" +
|
||||
updateIssuer +
|
||||
":" +
|
||||
updateAccount +
|
||||
"?algorithm=${updatedAlgo.name}&digits=$updatedDigits&issuer=" +
|
||||
updateIssuer +
|
||||
"&period=$updatePeriod&secret=" +
|
||||
updatedSecret,
|
||||
generatedID: generatedID,
|
||||
);
|
||||
}
|
||||
|
||||
static Code fromAccountAndSecret(
|
||||
String account,
|
||||
String issuer,
|
||||
|
|
|
@ -117,17 +117,24 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
|
|||
return;
|
||||
}
|
||||
try {
|
||||
final code = Code.fromAccountAndSecret(
|
||||
_accountController.text.trim(),
|
||||
_issuerController.text.trim(),
|
||||
_secretController.text.trim().replaceAll(' ', ''),
|
||||
);
|
||||
final account = _accountController.text.trim();
|
||||
final issuer = _issuerController.text.trim();
|
||||
final secret =
|
||||
_secretController.text.trim().replaceAll(' ', '');
|
||||
final Code newCode = widget.code == null
|
||||
? Code.fromAccountAndSecret(
|
||||
account,
|
||||
issuer,
|
||||
secret,
|
||||
)
|
||||
: widget.code!.copyWith(
|
||||
account: account,
|
||||
issuer: issuer,
|
||||
secret: secret,
|
||||
);
|
||||
// Verify the validity of the code
|
||||
getTotp(code);
|
||||
if (widget.code != null) {
|
||||
code.generatedID = widget.code!.generatedID;
|
||||
}
|
||||
Navigator.of(context).pop(code);
|
||||
getTotp(newCode);
|
||||
Navigator.of(context).pop(newCode);
|
||||
} catch (e) {
|
||||
_showIncorrectDetailsDialog(context);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue