mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-26 04:48:51 +00:00
Send answers back to the server
This commit is contained in:
parent
3ffb24f7c5
commit
44ea647624
@ -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(
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user