diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-08-20 10:01:11 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-08-20 10:01:11 +0200 |
commit | 6afa5d2c09b5548d8c306af0125015389e895827 (patch) | |
tree | fa1035488a7e5ade0f50bbf934dec0187b4d3d20 | |
parent | 322eb1f4337c3ac145022b030068d7d41a027ece (diff) | |
download | anastasis-gtk-6afa5d2c09b5548d8c306af0125015389e895827.tar.gz anastasis-gtk-6afa5d2c09b5548d8c306af0125015389e895827.tar.bz2 anastasis-gtk-6afa5d2c09b5548d8c306af0125015389e895827.zip |
add IBAN dialog
-rw-r--r-- | contrib/anastasis_gtk_auth_add_iban.glade | 15 | ||||
-rw-r--r-- | contrib/anastasis_gtk_main_window.glade | 28 | ||||
-rw-r--r-- | src/anastasis/Makefile.am | 1 | ||||
-rw-r--r-- | src/anastasis/anastasis-gtk_handle-method-iban.c | 169 |
4 files changed, 205 insertions, 8 deletions
diff --git a/contrib/anastasis_gtk_auth_add_iban.glade b/contrib/anastasis_gtk_auth_add_iban.glade index a1676a4..8aefa69 100644 --- a/contrib/anastasis_gtk_auth_add_iban.glade +++ b/contrib/anastasis_gtk_auth_add_iban.glade @@ -30,9 +30,8 @@ Author: Belen Pena, Christian Grothoff, Dennis Neufeld <!-- interface-authors Belen Pena, Christian Grothoff, Dennis Neufeld --> <object class="GtkDialog" id="anastasis_gtk_b_iban_dialog"> <property name="can-focus">False</property> - <property name="icon">outline_email_black_24dp.png</property> <property name="type-hint">dialog</property> - <signal name="response" handler="anastasis_gtk_b_email_dialog_response_cb" swapped="no"/> + <signal name="response" handler="anastasis_gtk_b_iban_dialog_response_cb" swapped="no"/> <child internal-child="vbox"> <object class="GtkBox"> <property name="can-focus">False</property> @@ -43,7 +42,7 @@ Author: Belen Pena, Christian Grothoff, Dennis Neufeld <property name="can-focus">False</property> <property name="layout-style">end</property> <child> - <object class="GtkButton" id="anastasis_gtk_b_email_dialog_btn_cancel"> + <object class="GtkButton" id="anastasis_gtk_b_iban_dialog_btn_cancel"> <property name="label">gtk-cancel</property> <property name="visible">True</property> <property name="can-focus">False</property> @@ -58,7 +57,7 @@ Author: Belen Pena, Christian Grothoff, Dennis Neufeld </packing> </child> <child> - <object class="GtkButton" id="anastasis_gtk_b_email_dialog_btn_ok"> + <object class="GtkButton" id="anastasis_gtk_b_iban_dialog_btn_ok"> <property name="label">gtk-ok</property> <property name="visible">True</property> <property name="sensitive">False</property> @@ -173,8 +172,8 @@ transfer from the account you provided here.</property> </object> </child> <action-widgets> - <action-widget response="-6">anastasis_gtk_b_email_dialog_btn_cancel</action-widget> - <action-widget response="-5">anastasis_gtk_b_email_dialog_btn_ok</action-widget> + <action-widget response="-6">anastasis_gtk_b_iban_dialog_btn_cancel</action-widget> + <action-widget response="-5">anastasis_gtk_b_iban_dialog_btn_ok</action-widget> </action-widgets> <child type="titlebar"> <object class="GtkLabel"> @@ -184,8 +183,8 @@ transfer from the account you provided here.</property> </object> </child> <action-widgets> - <action-widget response="-6">anastasis_gtk_b_email_dialog_btn_cancel</action-widget> - <action-widget response="-5">anastasis_gtk_b_email_dialog_btn_ok</action-widget> + <action-widget response="-6">anastasis_gtk_b_iban_dialog_btn_cancel</action-widget> + <action-widget response="-5">anastasis_gtk_b_iban_dialog_btn_ok</action-widget> </action-widgets> </object> </interface> diff --git a/contrib/anastasis_gtk_main_window.glade b/contrib/anastasis_gtk_main_window.glade index 858fda8..ae0d8e3 100644 --- a/contrib/anastasis_gtk_main_window.glade +++ b/contrib/anastasis_gtk_main_window.glade @@ -242,12 +242,24 @@ Author: Christian Grothoff, Dennis Neufeld <property name="step-increment">1</property> <property name="page-increment">10</property> </object> + <object class="GtkImage" id="image_iban"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="stock">gtk-missing-image</property> + </object> <object class="GtkImage" id="image_sms"> <property name="visible">True</property> <property name="can-focus">False</property> <property name="margin-end">5</property> <property name="pixbuf">outline_stay_current_portrait_black_24dp.png</property> </object> + <object class="GtkImage" id="image_sms1"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="margin-right">5</property> + <property name="margin-end">5</property> + <property name="pixbuf">outline_stay_current_portrait_black_24dp.png</property> + </object> <object class="GtkImage" id="open_file_image"> <property name="visible">True</property> <property name="can-focus">False</property> @@ -1929,6 +1941,22 @@ with <a href="https://www.ngi.eu/ngi-projects/ledger/">funding</a> f <property name="position">4</property> </packing> </child> + <child> + <object class="GtkButton" id="anastasis_gtk_btn_add_auth_iban"> + <property name="label" translatable="yes">IBAN</property> + <property name="visible">True</property> + <property name="can-focus">True</property> + <property name="receives-default">True</property> + <property name="image">image_iban</property> + <signal name="clicked" handler="anastasis_gtk_btn_add_auth_iban_clicked_cb" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="padding">5</property> + <property name="position">5</property> + </packing> + </child> </object> </child> <child type="label"> diff --git a/src/anastasis/Makefile.am b/src/anastasis/Makefile.am index af3ed4e..9ca420d 100644 --- a/src/anastasis/Makefile.am +++ b/src/anastasis/Makefile.am @@ -40,6 +40,7 @@ anastasis_gtk_SOURCES = \ anastasis-gtk_handle-main-window-forward-clicked.h \ anastasis-gtk_handle-main-window-back-clicked.c \ anastasis-gtk_handle-method-email.c \ + anastasis-gtk_handle-method-iban.c \ anastasis-gtk_handle-method-post.c \ anastasis-gtk_handle-method-question.c \ anastasis-gtk_handle-method-sms.c \ diff --git a/src/anastasis/anastasis-gtk_handle-method-iban.c b/src/anastasis/anastasis-gtk_handle-method-iban.c new file mode 100644 index 0000000..104b4c3 --- /dev/null +++ b/src/anastasis/anastasis-gtk_handle-method-iban.c @@ -0,0 +1,169 @@ +/* + This file is part of anastasis-gtk. + Copyright (C) 2021 Anastasis SARL + + Anastasis is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + Anastasis is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Anastasis; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +/** + * @file src/anastasis/anastasis-gtk_handle-method-iban.c + * @brief Handle dialogs for security iban + * @author Christian Grothoff + */ +#include <gnunet/platform.h> +#include <gnunet/gnunet_util_lib.h> +#include "anastasis-gtk_action.h" +#include "anastasis-gtk_helper.h" +#include "anastasis-gtk_handle-identity-changed.h" +#include <jansson.h> + + +/** + * Return obfuscated variant of an IBAN. + * + * @param iban input address + * @return obfuscated version, NULL on errors + */ +static char * +mask_iban (const char *iban) +{ + size_t slen = strlen (iban); + char *result; + + GNUNET_assert (slen > 5); + GNUNET_asprintf (&result, + "%2s...%s", + iban, + &iban[slen - 5]); + return result; +} + + +/** + * Function called from the security-iban dialog upon completion. + * + * @param dialog the pseudonym selection dialog + * @param response_id response code from the dialog + * @param user_data the builder of the dialog + */ +void +anastasis_gtk_b_iban_dialog_response_cb (GtkDialog *dialog, + gint response_id, + gpointer user_data) +{ + GtkBuilder *builder = GTK_BUILDER (user_data); + GtkEntry *q; + const char *qs; + json_t *args; + char *ins; + char *pe; + + if (GTK_RESPONSE_OK != response_id) + { + gtk_widget_destroy (GTK_WIDGET (dialog)); + g_object_unref (G_OBJECT (builder)); + return; + } + q = GTK_ENTRY (gtk_builder_get_object (builder, + "anastasis_gtk_b_iban_dialog_iban_entry")); + qs = gtk_entry_get_text (q); + pe = mask_iban (qs); + GNUNET_asprintf (&ins, + _ ("IBAN %s"), + pe); + GNUNET_free (pe); + args = json_pack ("{ s:{s:s, s:o, s:s}}", + "authentication_method", + "type", + "iban", + "challenge", + GNUNET_JSON_from_data (qs, + strlen (qs)), + "instructions", + ins); + GNUNET_free (ins); + gtk_widget_destroy (GTK_WIDGET (dialog)); + g_object_unref (G_OBJECT (builder)); + AG_freeze (); + AG_ra = ANASTASIS_redux_action (AG_redux_state, + "add_authentication", + args, + &AG_action_cb, + NULL); + json_decref (args); +} + + +void +anastasis_gtk_b_iban_dialog_mailaddress_entry_changed_cb (GtkEntry *entry, + gpointer user_data) +{ + GtkBuilder *builder = GTK_BUILDER (user_data); + GtkEntry *q; + const char *qs; + char *err; + + q = GTK_ENTRY (gtk_builder_get_object (builder, + "anastasis_gtk_b_iban_dialog_mailaddress_entry")); + qs = gtk_entry_get_text (q); + err = TALER_iban_validate (qs); + gtk_widget_set_sensitive ( + GTK_WIDGET (gtk_builder_get_object (builder, + "anastasis_gtk_b_iban_dialog_btn_ok")), + NULL == err); + if (NULL != err) + { + /* TODO: show _inside_ the dialog instead of in logs... */ + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "IBAN `%s' invalid: %s\n", + qs, + err); + } + GNUNET_free (err); +} + + +/** + * Callback invoked if the the "secure iban"-button is clicked. + * + * @param object + * @param user_data unused + */ +void +anastasis_gtk_btn_add_auth_iban_clicked_cb (GObject *object, + gpointer user_data) +{ + GtkWidget *ad; + GtkBuilder *builder; + + builder = GNUNET_GTK_get_new_builder ("anastasis_gtk_auth_add_iban.glade", + NULL); + if (NULL == builder) + { + GNUNET_break (0); + return; + } + ad = GTK_WIDGET (gtk_builder_get_object (builder, + "anastasis_gtk_b_iban_dialog")); + { + GtkWidget *toplevel; + + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (object)); + gtk_window_set_transient_for (GTK_WINDOW (ad), + GTK_WINDOW (toplevel)); + gtk_window_present (GTK_WINDOW (ad)); + } +} |