[gnome-software/wip/williamhua/reviews] Revert "Use login dialog to get OAuth credentials"



commit 797d3fcf6dd38ce29baada9df9319536a2854d34
Author: William Hua <william hua canonical com>
Date:   Mon Feb 8 09:29:36 2016 -0500

    Revert "Use login dialog to get OAuth credentials"
    
    This reverts commit 79cb67e744d51fae9dc392adddcef749e684fdf3.

 src/gnome-software.gresource.xml       |    1 -
 src/plugins/gs-plugin-ubuntu-reviews.c |  427 +-------------------------------
 2 files changed, 6 insertions(+), 422 deletions(-)
---
diff --git a/src/gnome-software.gresource.xml b/src/gnome-software.gresource.xml
index 22928a3..710d8da 100644
--- a/src/gnome-software.gresource.xml
+++ b/src/gnome-software.gresource.xml
@@ -27,7 +27,6 @@
   <file preprocess="xml-stripblanks">gs-star-widget.ui</file>
   <file preprocess="xml-stripblanks">gs-update-dialog.ui</file>
   <file preprocess="xml-stripblanks">gs-upgrade-banner.ui</file>
-  <file preprocess="xml-stripblanks">plugins/ubuntu-one.ui</file>
   <file preprocess="xml-stripblanks">org.freedesktop.PackageKit.xml</file>
   <file>gtk-style.css</file>
   <file>gtk-style-hc.css</file>
diff --git a/src/plugins/gs-plugin-ubuntu-reviews.c b/src/plugins/gs-plugin-ubuntu-reviews.c
index ef5b34e..6a2d49e 100644
--- a/src/plugins/gs-plugin-ubuntu-reviews.c
+++ b/src/plugins/gs-plugin-ubuntu-reviews.c
@@ -22,7 +22,6 @@
 #include <config.h>
 
 #include <math.h>
-#include <glib/gi18n.h>
 #include <libsoup/soup.h>
 #include <json-glib/json-glib.h>
 #include <oauth.h>
@@ -36,10 +35,6 @@ struct GsPluginPrivate {
        sqlite3         *db;
        gsize            db_loaded;
        SoupSession     *session;
-       gchar           *consumer_key;
-       gchar           *consumer_secret;
-       gchar           *token_key;
-       gchar           *token_secret;
 };
 
 typedef struct {
@@ -56,7 +51,6 @@ gs_plugin_get_name (void)
        return "ubuntu-reviews";
 }
 
-#define UBUNTU_LOGIN_SERVER            "https://login.ubuntu.com";
 #define UBUNTU_REVIEWS_SERVER          "https://reviews.ubuntu.com/reviews";
 
 /* Download new stats every three months */
@@ -92,14 +86,10 @@ gs_plugin_get_deps (GsPlugin *plugin)
 void
 gs_plugin_destroy (GsPlugin *plugin)
 {
-       GsPluginPrivate *priv = plugin->priv;
-
-       g_clear_pointer (&priv->token_secret, g_free);
-       g_clear_pointer (&priv->token_key, g_free);
-       g_clear_pointer (&priv->consumer_secret, g_free);
-       g_clear_pointer (&priv->consumer_key, g_free);
-       g_clear_pointer (&priv->db, sqlite3_close);
-       g_clear_object (&priv->session);
+       if (plugin->priv->db != NULL)
+               sqlite3_close (plugin->priv->db);
+       if (plugin->priv->session != NULL)
+               g_object_unref (plugin->priv->session);
 }
 
 static gboolean
@@ -800,6 +790,8 @@ set_package_review (GsPlugin *plugin,
 
        /* Write review into database so we can easily access it */
 
+       /* Load OAuth token */
+
        /*
        result = send_review (plugin,
                              review,
@@ -814,410 +806,6 @@ set_package_review (GsPlugin *plugin,
        return result;
 }
 
-typedef struct
-{
-       GsPlugin *plugin;
-       GtkBuilder *builder;
-       GtkWidget *dialog;
-       GtkWidget *cancel;
-       GtkWidget *back;
-       GtkWidget *next;
-       GtkWidget *stack;
-       GtkWidget *email;
-       GtkWidget *password;
-       GtkWidget *passcode;
-       GtkWidget *stack0;
-       GtkWidget *status00;
-       GtkWidget *box0;
-       GtkWidget *status01;
-       GtkWidget *stack1;
-       GtkWidget *status10;
-       GtkWidget *box1;
-       GtkWidget *status11;
-} LoginContext;
-
-static gboolean
-is_email_address (const gchar *text)
-{
-       text = g_utf8_strchr (text, -1, '@');
-
-       if (text == NULL)
-               return FALSE;
-
-       text = g_utf8_strchr (text + 1, -1, '.');
-
-       if (text == NULL)
-               return FALSE;
-
-       return text[1] != '\0';
-}
-
-static void
-update_dialog (LoginContext *context)
-{
-       if (g_str_equal (gtk_stack_get_visible_child_name (GTK_STACK (context->stack)), "page0")) {
-               gtk_widget_set_visible (context->cancel, TRUE);
-               gtk_widget_set_visible (context->back, FALSE);
-               gtk_widget_set_sensitive (context->next, is_email_address (gtk_entry_get_text (GTK_ENTRY 
(context->email))) &&
-                                                        gtk_entry_get_text_length (GTK_ENTRY 
(context->password)) > 0);
-               gtk_button_set_label (GTK_BUTTON (context->next), _("_Next"));
-       } else if (g_str_equal (gtk_stack_get_visible_child_name (GTK_STACK (context->stack)), "page1")) {
-               gtk_widget_set_visible (context->cancel, TRUE);
-               gtk_widget_set_visible (context->back, TRUE);
-               gtk_widget_set_sensitive (context->next, gtk_entry_get_text_length (GTK_ENTRY 
(context->passcode)) > 0);
-               gtk_button_set_label (GTK_BUTTON (context->next), _("_Next"));
-       } else if (g_str_equal (gtk_stack_get_visible_child_name (GTK_STACK (context->stack)), "page2")) {
-               gtk_widget_set_visible (context->cancel, FALSE);
-               gtk_widget_set_visible (context->back, FALSE);
-               gtk_widget_set_sensitive (context->next, TRUE);
-               gtk_button_set_label (GTK_BUTTON (context->next), _("_Close"));
-       }
-}
-
-static void
-dialog_show_cb (GtkWidget *widget,
-                gpointer   user_data)
-{
-       update_dialog (user_data);
-}
-
-static void
-cancel_clicked_cb (GtkButton *button,
-                   gpointer   user_data)
-{
-       LoginContext *context = user_data;
-
-       gtk_dialog_response (GTK_DIALOG (context->dialog), GTK_RESPONSE_CANCEL);
-}
-
-static void
-back_clicked_cb (GtkButton *button,
-                 gpointer   user_data)
-{
-       LoginContext *context = user_data;
-
-       if (g_str_equal (gtk_stack_get_visible_child_name (GTK_STACK (context->stack)), "page1")) {
-               gtk_stack_set_visible_child_name (GTK_STACK (context->stack), "page0");
-               update_dialog (context);
-       }
-}
-
-static guint
-send_variant_request (SoupSession  *session,
-                      const gchar  *method,
-                      const gchar  *host,
-                      const gchar  *uri,
-                      GVariant     *request,
-                      GVariant    **response,
-                      GError      **error)
-{
-       gchar *data;
-       gsize length;
-       gchar *url;
-       SoupMessage *message;
-       guint response_code;
-       GBytes *bytes;
-
-       g_return_val_if_fail (session != NULL, 0);
-       g_return_val_if_fail (method != NULL, 0);
-       g_return_val_if_fail (host != NULL, 0);
-       g_return_val_if_fail (uri != NULL, 0);
-       g_return_val_if_fail (request != NULL, 0);
-
-       g_variant_ref_sink (request);
-       data = json_gvariant_serialize_data (request, &length);
-       g_variant_unref (request);
-
-       url = g_strdup_printf ("%s%s", host, uri);
-       message = soup_message_new (method, url);
-       g_free (url);
-
-       soup_message_set_request (message, "application/json", SOUP_MEMORY_TAKE, data, length);
-       response_code = soup_session_send_message (session, message);
-       g_object_get (message, SOUP_MESSAGE_RESPONSE_BODY_DATA, &bytes, NULL);
-       g_object_unref (message);
-
-       data = g_bytes_unref_to_data (bytes, &length);
-
-       if (response != NULL)
-               *response = json_gvariant_deserialize_data (data, length, NULL, error);
-
-       g_free (data);
-
-       return response_code;
-}
-
-static void
-send_first_factor (LoginContext *context)
-{
-       GVariant *request;
-       GVariant *response;
-       guint response_code;
-       const gchar *code;
-       GError *error = NULL;
-
-       gtk_widget_set_sensitive (context->cancel, FALSE);
-       gtk_widget_set_sensitive (context->back, FALSE);
-       gtk_widget_set_sensitive (context->next, FALSE);
-       g_object_set (context->email, "editable", FALSE, NULL);
-       g_object_set (context->password, "editable", FALSE, NULL);
-
-       gtk_label_set_text (GTK_LABEL (context->status01), _("Signing into Ubuntu One..."));
-       gtk_stack_set_visible_child_name (GTK_STACK (context->stack0), "box0");
-
-       request = g_variant_new_parsed ("{ 'token_name' : 'GNOME Software', 'email' : %s, 'password' : %s }",
-                                       gtk_entry_get_text (GTK_ENTRY (context->email)),
-                                       gtk_entry_get_text (GTK_ENTRY (context->password)));
-
-       response_code = send_variant_request (context->plugin->priv->session,
-                                             SOUP_METHOD_POST,
-                                             UBUNTU_LOGIN_SERVER,
-                                             "/api/v2/tokens/oauth",
-                                             request,
-                                             &response,
-                                             &error);
-
-       gtk_label_set_text (GTK_LABEL (context->status00), NULL);
-       gtk_stack_set_visible_child_name (GTK_STACK (context->stack0), "status00");
-
-       g_object_set (context->password, "editable", TRUE, NULL);
-       g_object_set (context->email, "editable", TRUE, NULL);
-       gtk_widget_set_sensitive (context->next, TRUE);
-       gtk_widget_set_sensitive (context->back, TRUE);
-       gtk_widget_set_sensitive (context->cancel, TRUE);
-
-       if (response != NULL) {
-               g_variant_ref_sink (response);
-
-               switch (response_code) {
-               case 200:
-               case 201:
-                       g_clear_pointer (&context->plugin->priv->token_secret, g_free);
-                       g_clear_pointer (&context->plugin->priv->token_key, g_free);
-                       g_clear_pointer (&context->plugin->priv->consumer_secret, g_free);
-                       g_clear_pointer (&context->plugin->priv->consumer_key, g_free);
-
-                       g_variant_lookup (response, "consumer_key", "s", 
&context->plugin->priv->consumer_key);
-                       g_variant_lookup (response, "consumer_secret", "s", 
&context->plugin->priv->consumer_secret);
-                       g_variant_lookup (response, "token_key", "s", &context->plugin->priv->token_key);
-                       g_variant_lookup (response, "token_secret", "s", 
&context->plugin->priv->token_secret);
-
-                       gtk_stack_set_visible_child_name (GTK_STACK (context->stack), "page2");
-                       update_dialog (context);
-                       break;
-
-               case 401:
-               case 403:
-               case 429:
-                       g_variant_lookup (response, "code", "&s", &code);
-
-                       if (code == NULL)
-                               code = "";
-
-                       if (g_str_equal (code, "TWOFACTOR_REQUIRED")) {
-                               gtk_stack_set_visible_child_name (GTK_STACK (context->stack), "page1");
-                               update_dialog (context);
-                       } else if (g_str_equal (code, "INVALID_CREDENTIALS")) {
-                               gtk_label_set_text (GTK_LABEL (context->status00), _("Incorrect 
email/password"));
-                       } else if (g_str_equal (code, "ACCOUNT_SUSPENDED")) {
-                               gtk_label_set_text (GTK_LABEL (context->status00), _("This account is 
suspended"));
-                       } else if (g_str_equal (code, "ACCOUNT_DEACTIVATED")) {
-                               gtk_label_set_text (GTK_LABEL (context->status00), _("This account is 
deactivated"));
-                       } else if (g_str_equal (code, "EMAIL_INVALIDATED")) {
-                               gtk_label_set_text (GTK_LABEL (context->status00), _("This email is 
invalidated"));
-                       } else if (g_str_equal (code, "TWOFACTOR_FAILURE")) {
-                               gtk_label_set_text (GTK_LABEL (context->status00), _("Two-factor 
authentication failed"));
-                       } else if (g_str_equal (code, "PASSWORD_POLICY_ERROR")) {
-                               gtk_label_set_text (GTK_LABEL (context->status00), _("Password reset 
required"));
-                       } else if (g_str_equal (code, "TOO_MANY_REQUESTS")) {
-                               gtk_label_set_text (GTK_LABEL (context->status00), _("Too many requests"));
-                       }
-
-                       break;
-               }
-
-               g_variant_unref (response);
-       }
-}
-
-static void
-send_second_factor (LoginContext *context)
-{
-       GVariant *request;
-       GVariant *response;
-       guint response_code;
-       const gchar *code;
-       GError *error = NULL;
-
-       gtk_widget_set_sensitive (context->cancel, FALSE);
-       gtk_widget_set_sensitive (context->back, FALSE);
-       gtk_widget_set_sensitive (context->next, FALSE);
-       g_object_set (context->passcode, "editable", FALSE, NULL);
-
-       gtk_label_set_text (GTK_LABEL (context->status11), _("Signing into Ubuntu One..."));
-       gtk_stack_set_visible_child_name (GTK_STACK (context->stack1), "box1");
-
-       request = g_variant_new_parsed ("{ 'token_name' : 'GNOME Software', 'email' : %s, 'password' : %s, 
'otp' : %s }",
-                                       gtk_entry_get_text (GTK_ENTRY (context->email)),
-                                       gtk_entry_get_text (GTK_ENTRY (context->password)),
-                                       gtk_entry_get_text (GTK_ENTRY (context->passcode)));
-
-       response_code = send_variant_request (context->plugin->priv->session,
-                                             SOUP_METHOD_POST,
-                                             UBUNTU_LOGIN_SERVER,
-                                             "/api/v2/tokens/oauth",
-                                             request,
-                                             &response,
-                                             &error);
-
-       gtk_label_set_text (GTK_LABEL (context->status10), NULL);
-       gtk_stack_set_visible_child_name (GTK_STACK (context->stack1), "status10");
-
-       g_object_set (context->passcode, "editable", TRUE, NULL);
-       gtk_widget_set_sensitive (context->next, TRUE);
-       gtk_widget_set_sensitive (context->back, TRUE);
-       gtk_widget_set_sensitive (context->cancel, TRUE);
-
-       if (response != NULL) {
-               g_variant_ref_sink (response);
-
-               switch (response_code) {
-               case 200:
-               case 201:
-                       g_clear_pointer (&context->plugin->priv->token_secret, g_free);
-                       g_clear_pointer (&context->plugin->priv->token_key, g_free);
-                       g_clear_pointer (&context->plugin->priv->consumer_secret, g_free);
-                       g_clear_pointer (&context->plugin->priv->consumer_key, g_free);
-
-                       g_variant_lookup (response, "consumer_key", "s", 
&context->plugin->priv->consumer_key);
-                       g_variant_lookup (response, "consumer_secret", "s", 
&context->plugin->priv->consumer_secret);
-                       g_variant_lookup (response, "token_key", "s", &context->plugin->priv->token_key);
-                       g_variant_lookup (response, "token_secret", "s", 
&context->plugin->priv->token_secret);
-
-                       gtk_stack_set_visible_child_name (GTK_STACK (context->stack), "page2");
-                       update_dialog (context);
-                       break;
-
-               case 401:
-               case 403:
-               case 429:
-                       g_variant_lookup (response, "code", "&s", &code);
-
-                       if (code == NULL)
-                               code = "";
-
-                       if (g_str_equal (code, "TWOFACTOR_REQUIRED")) {
-                               gtk_label_set_text (GTK_LABEL (context->status10), _("Two-factor 
authentication failed"));
-                       } else if (g_str_equal (code, "INVALID_CREDENTIALS")) {
-                               gtk_label_set_text (GTK_LABEL (context->status10), _("Incorrect 
email/password"));
-                       } else if (g_str_equal (code, "ACCOUNT_SUSPENDED")) {
-                               gtk_label_set_text (GTK_LABEL (context->status10), _("This account is 
suspended"));
-                       } else if (g_str_equal (code, "ACCOUNT_DEACTIVATED")) {
-                               gtk_label_set_text (GTK_LABEL (context->status10), _("This account is 
deactivated"));
-                       } else if (g_str_equal (code, "EMAIL_INVALIDATED")) {
-                               gtk_label_set_text (GTK_LABEL (context->status10), _("This email is 
invalidated"));
-                       } else if (g_str_equal (code, "TWOFACTOR_FAILURE")) {
-                               gtk_label_set_text (GTK_LABEL (context->status10), _("Two-factor 
authentication failed"));
-                       } else if (g_str_equal (code, "PASSWORD_POLICY_ERROR")) {
-                               gtk_label_set_text (GTK_LABEL (context->status10), _("Password reset 
required"));
-                       } else if (g_str_equal (code, "TOO_MANY_REQUESTS")) {
-                               gtk_label_set_text (GTK_LABEL (context->status10), _("Too many requests"));
-                       }
-
-                       break;
-               }
-
-               g_variant_unref (response);
-       }
-}
-
-static void
-next_clicked_cb (GtkButton *button,
-                 gpointer   user_data)
-{
-       LoginContext *context = user_data;
-
-       if (g_str_equal (gtk_stack_get_visible_child_name (GTK_STACK (context->stack)), "page0")) {
-               send_first_factor (context);
-       } else if (g_str_equal (gtk_stack_get_visible_child_name (GTK_STACK (context->stack)), "page1")) {
-               send_second_factor (context);
-       } else if (g_str_equal (gtk_stack_get_visible_child_name (GTK_STACK (context->stack)), "page2")) {
-               gtk_dialog_response (GTK_DIALOG (context->dialog), GTK_RESPONSE_CLOSE);
-       }
-}
-
-static void
-email_notify_cb (GObject    *object,
-                 GParamSpec *pspec,
-                 gpointer    user_data)
-{
-       update_dialog (user_data);
-}
-
-static void
-password_notify_cb (GObject    *object,
-                    GParamSpec *pspec,
-                    gpointer    user_data)
-{
-       update_dialog (user_data);
-}
-
-static void
-passcode_notify_cb (GObject    *object,
-                    GParamSpec *pspec,
-                    gpointer    user_data)
-{
-       update_dialog (user_data);
-}
-
-static gboolean
-sign_into_ubuntu_one (GsPlugin  *plugin,
-                      GError   **error)
-{
-       GsPluginPrivate *priv = plugin->priv;
-       LoginContext context = { NULL };
-
-       if (priv->consumer_key && priv->consumer_secret && priv->token_key && priv->token_secret)
-               return TRUE;
-
-       g_clear_pointer (&priv->token_secret, g_free);
-       g_clear_pointer (&priv->token_key, g_free);
-       g_clear_pointer (&priv->consumer_secret, g_free);
-       g_clear_pointer (&priv->consumer_key, g_free);
-
-       context.plugin = plugin;
-       context.builder = gtk_builder_new_from_resource ("/org/gnome/Software/plugins/ubuntu-one.ui");
-       context.dialog = GTK_WIDGET (gtk_builder_get_object (context.builder, "dialog"));
-       context.cancel = GTK_WIDGET (gtk_builder_get_object (context.builder, "cancel"));
-       context.back = GTK_WIDGET (gtk_builder_get_object (context.builder, "back"));
-       context.next = GTK_WIDGET (gtk_builder_get_object (context.builder, "next"));
-       context.stack = GTK_WIDGET (gtk_builder_get_object (context.builder, "stack"));
-       context.email = GTK_WIDGET (gtk_builder_get_object (context.builder, "email"));
-       context.password = GTK_WIDGET (gtk_builder_get_object (context.builder, "password"));
-       context.passcode = GTK_WIDGET (gtk_builder_get_object (context.builder, "passcode"));
-       context.stack0 = GTK_WIDGET (gtk_builder_get_object (context.builder, "stack0"));
-       context.status00 = GTK_WIDGET (gtk_builder_get_object (context.builder, "status00"));
-       context.box0 = GTK_WIDGET (gtk_builder_get_object (context.builder, "box0"));
-       context.status01 = GTK_WIDGET (gtk_builder_get_object (context.builder, "status01"));
-       context.stack1 = GTK_WIDGET (gtk_builder_get_object (context.builder, "stack1"));
-       context.status10 = GTK_WIDGET (gtk_builder_get_object (context.builder, "status10"));
-       context.box1 = GTK_WIDGET (gtk_builder_get_object (context.builder, "box1"));
-       context.status11 = GTK_WIDGET (gtk_builder_get_object (context.builder, "status11"));
-
-       g_signal_connect (context.dialog, "show", G_CALLBACK (dialog_show_cb), &context);
-       g_signal_connect (context.cancel, "clicked", G_CALLBACK (cancel_clicked_cb), &context);
-       g_signal_connect (context.back, "clicked", G_CALLBACK (back_clicked_cb), &context);
-       g_signal_connect (context.next, "clicked", G_CALLBACK (next_clicked_cb), &context);
-       g_signal_connect (context.email, "notify::text", G_CALLBACK (email_notify_cb), &context);
-       g_signal_connect (context.password, "notify::text", G_CALLBACK (password_notify_cb), &context);
-       g_signal_connect (context.passcode, "notify::text", G_CALLBACK (passcode_notify_cb), &context);
-
-       gtk_dialog_run (GTK_DIALOG (context.dialog));
-
-       gtk_widget_destroy (context.dialog);
-       g_object_unref (context.builder);
-}
-
 gboolean
 gs_plugin_app_set_review (GsPlugin *plugin,
                          GsApp *app,
@@ -1252,9 +840,6 @@ gs_plugin_app_set_review (GsPlugin *plugin,
        if (!setup_networking (plugin, error))
                return FALSE;
 
-       if (!sign_into_ubuntu_one (plugin, error))
-               return FALSE;
-
        /* set rating for each package */
        for (i = 0; i < sources->len; i++) {
                package_name = g_ptr_array_index (sources, i);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]