mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-02-16 21:52:38 +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"])
|
.getObject()["questions"])
|
||||||
.cast<String>();
|
.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
|
/// Get current user ID from the server
|
||||||
Future<int> _downloadCurrentUserID() async {
|
Future<int> _downloadCurrentUserID() async {
|
||||||
final response = await APIRequest(
|
final response = await APIRequest(
|
||||||
|
@ -213,14 +213,26 @@ class _ResetPasswordBodyState extends SafeState<_ResetPasswordBody> {
|
|||||||
_canSubmitAnswers ? (s) => _submitSecurityAnswers() : null,
|
_canSubmitAnswers ? (s) => _submitSecurityAnswers() : null,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
alignLabelWithHint: false,
|
alignLabelWithHint: false,
|
||||||
labelText: tr("Answer %num%", args: {"num": id.toString()})),
|
labelText:
|
||||||
|
tr("Answer %num%", args: {"num": (id + 1).toString()})),
|
||||||
),
|
),
|
||||||
_Spacer()
|
_Spacer()
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Submit security answers
|
/// 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 {
|
class _Spacer extends StatelessWidget {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user