diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-09-26 15:52:46 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-09-26 15:52:46 +0200 |
commit | 3b5809bcf0c071eaaaeaee2a15e2b87c32202235 (patch) | |
tree | 892b3c0c8a596d93f86e871b2b07c6a23d53ff7b /src/anastasis/anastasis-gtk_action.c | |
parent | c07ae7d8d5f39a94b3792c9267d8463746f79ba8 (diff) | |
download | anastasis-gtk-3b5809bcf0c071eaaaeaee2a15e2b87c32202235.tar.gz anastasis-gtk-3b5809bcf0c071eaaaeaee2a15e2b87c32202235.tar.bz2 anastasis-gtk-3b5809bcf0c071eaaaeaee2a15e2b87c32202235.zip |
add dialog to answer TOTP challenges
Diffstat (limited to 'src/anastasis/anastasis-gtk_action.c')
-rw-r--r-- | src/anastasis/anastasis-gtk_action.c | 73 |
1 files changed, 71 insertions, 2 deletions
diff --git a/src/anastasis/anastasis-gtk_action.c b/src/anastasis/anastasis-gtk_action.c index 5d4b461..87e06bc 100644 --- a/src/anastasis/anastasis-gtk_action.c +++ b/src/anastasis/anastasis-gtk_action.c @@ -2533,6 +2533,15 @@ action_challenge_paying (void) * Render challenge feedback for challenge @a uuid_str in a dialog of * @a builder in the label under @a target_widget. * + * Useful in case the operation previously failed at the + * server and we have some useful information to return + * to the user. + * + * FIXME: only do it AFTER the first attempt of the + * user to enter a code, and/or change what the + * server returns so we do NOT render a confusing + * error message on first use! + * * @param builder a builder to get widgets from * @param target_widget the widget to upate * @param uuid_str the UUID to render feedback for @@ -2735,7 +2744,6 @@ diag_question (const json_t *details) uuid_str = json_string_value (json_object_get (details, "uuid")); - /* Why do we do this? */ render_feedback (builder, "anastasis_gtk_c_question_error_label", uuid_str); @@ -2794,7 +2802,6 @@ diag_code (const json_t *details) "anastasis_gtk_c_challenge_label")); gtk_label_set_text (label, uuid_str); - /* Why do we do this? */ render_feedback (builder, "anastasis_gtk_c_code_error_label", uuid_str); @@ -2810,6 +2817,66 @@ diag_code (const json_t *details) /** + * Create a dialog for the user to enter an TOTP code. + * + * @param details details about the dialog to render + * @return dialog object + */ +static GtkDialog * +diag_totp (const json_t *details) +{ + GtkBuilder *builder; + const char *instructions; + const char *uuid_str; + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_string ("instructions", + &instructions), + GNUNET_JSON_spec_string ("uuid", + &uuid_str), + GNUNET_JSON_spec_end () + }; + + if (GNUNET_OK != + GNUNET_JSON_parse (details, + spec, + NULL, NULL)) + { + GNUNET_break (0); + json_dumpf (details, + stderr, + JSON_INDENT (2)); + return NULL; + } + + builder = GNUNET_GTK_get_new_builder ("anastasis_gtk_challenge_totp.glade", + NULL); + if (NULL == builder) + { + GNUNET_break (0); + return NULL; + } + { + GtkLabel *label; + + label = GTK_LABEL (gtk_builder_get_object (builder, + "challenge_instructions_label")); + gtk_label_set_text (label, + instructions); + } + render_feedback (builder, + "anastasis_gtk_c_totp_error_label", + uuid_str); + { + GtkDialog *ad; + + ad = GTK_DIALOG (gtk_builder_get_object (builder, + "anastasis_gtk_c_totp_dialog")); + return ad; + } +} + + +/** * Create a dialog for the user to make an IBAN transfer. * * @param details details about the dialog to render @@ -2941,6 +3008,8 @@ action_challenge_solving (void) .ctor = &diag_code }, { .type = gettext_noop ("iban"), .ctor = &diag_iban }, + { .type = gettext_noop ("totp"), + .ctor = &diag_totp }, { .type = NULL, .ctor = NULL } }; |