Merge pull request #112 from ente-io/109_fix_bug

Fix bug in edit code
This commit is contained in:
Neeraj Gupta 2023-04-30 09:29:38 +05:30 committed by GitHub
commit 08cc772ff1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 10 deletions

View file

@ -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,

View file

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