1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +00:00

Send answers back to the server

This commit is contained in:
Pierre HUBERT 2020-05-03 16:21:36 +02:00
parent 3ffb24f7c5
commit 44ea647624
2 changed files with 28 additions and 2 deletions

View File

@ -144,6 +144,20 @@ class AccountHelper {
.getObject()["questions"])
.cast<String>();
/// Validate given security answers
///
/// Throws an [Exception] in case of failure
///
/// Returns a password reset token in case of success
static Future<String> checkAnswers(
String email, List<String> answers) async =>
(await APIRequest.withoutLogin("account/check_security_answers")
.addString("email", email)
.addString("answers",
answers.map((f) => Uri.encodeComponent(f)).join("&"))
.execWithThrow())
.getObject()["reset_token"];
/// Get current user ID from the server
Future<int> _downloadCurrentUserID() async {
final response = await APIRequest(

View File

@ -213,14 +213,26 @@ class _ResetPasswordBodyState extends SafeState<_ResetPasswordBody> {
_canSubmitAnswers ? (s) => _submitSecurityAnswers() : null,
decoration: InputDecoration(
alignLabelWithHint: false,
labelText: tr("Answer %num%", args: {"num": id.toString()})),
labelText:
tr("Answer %num%", args: {"num": (id + 1).toString()})),
),
_Spacer()
],
);
/// Submit security answers
Future<void> _submitSecurityAnswers() async {}
Future<void> _submitSecurityAnswers() async {
_setLoading(true);
try {
final token = await AccountHelper.checkAnswers(_emailAddress, _answers);
print(token);
} catch (e, s) {
print("Could not submit security answers! $e\n$s");
showSimpleSnack(
context, tr("Could not validate these security answers!"));
}
_setLoading(false);
}
}
class _Spacer extends StatelessWidget {