[gnome-initial-setup/wip/pwithnall/misc-fixes: 12/70] password: Add password reminder




commit 9295bf223906eb1f9aa22aa68b287cfd3d49d554
Author: Alessandro Puccetti <alessandro kinvolk io>
Date:   Wed May 10 14:16:59 2017 +0200

    password: Add password reminder
    
    When creating the user account, offers the user a way to hint what
    is the password, in case they don't remind it later.
    
    Upstream: https://gitlab.gnome.org/GNOME/gnome-initial-setup/-/issues/56
    
    https://phabricator.endlessm.com/T1623

 .../pages/password/gis-password-page.c             | 27 +++++++++++--
 .../pages/password/gis-password-page.ui            | 46 ++++++++++++++++++++++
 2 files changed, 69 insertions(+), 4 deletions(-)
---
diff --git a/gnome-initial-setup/pages/password/gis-password-page.c 
b/gnome-initial-setup/pages/password/gis-password-page.c
index b0dd805f..e0962f33 100644
--- a/gnome-initial-setup/pages/password/gis-password-page.c
+++ b/gnome-initial-setup/pages/password/gis-password-page.c
@@ -46,6 +46,7 @@ struct _GisPasswordPagePrivate
   GtkWidget *password_strength;
   GtkWidget *password_explanation;
   GtkWidget *confirm_explanation;
+  GtkWidget *reminder_entry;
   GtkWidget *header;
 
   gboolean valid_confirm;
@@ -135,8 +136,9 @@ static gboolean
 page_validate (GisPasswordPage *page)
 {
   GisPasswordPagePrivate *priv = gis_password_page_get_instance_private (page);
+  gboolean has_reminder = (gtk_entry_get_text_length (GTK_ENTRY (priv->reminder_entry)) > 0);
 
-  return priv->valid_confirm;
+  return priv->valid_confirm && has_reminder;
 }
 
 static void
@@ -154,6 +156,8 @@ gis_password_page_save_data (GisPage  *gis_page,
   ActUser *act_user;
   UmAccountMode account_mode;
   const gchar *password = NULL;
+  gchar *sanitized_reminder;
+  const gchar *reminder;
 
   g_assert (gis_page->driver != NULL);
 
@@ -174,10 +178,14 @@ gis_password_page_save_data (GisPage  *gis_page,
 
   password = gtk_entry_get_text (GTK_ENTRY (priv->password_entry));
 
-  if (strlen (password) == 0)
+  if (strlen (password) == 0) {
     act_user_set_password_mode (act_user, ACT_USER_PASSWORD_MODE_NONE);
-  else
-    act_user_set_password (act_user, password, "");
+  } else {
+    reminder = gtk_entry_get_text (GTK_ENTRY (priv->reminder_entry));
+    sanitized_reminder = g_strstrip (g_strdup (reminder));
+    act_user_set_password (act_user, password, sanitized_reminder);
+    g_free (sanitized_reminder);
+  }
 
   if (!priv->parent_mode)
     gis_driver_set_user_permissions (gis_page->driver, act_user, password);
@@ -258,6 +266,14 @@ on_focusout (GisPasswordPage *page)
   return FALSE;
 }
 
+static void
+reminder_changed (GtkWidget       *w,
+                  GParamSpec      *pspec,
+                  GisPasswordPage *page)
+{
+  gis_page_set_complete (GIS_PAGE (page), page_validate (page));
+}
+
 static void
 password_changed (GtkWidget      *w,
                   GParamSpec     *pspec,
@@ -342,6 +358,8 @@ gis_password_page_constructed (GObject *object)
                             G_CALLBACK (on_focusout), page);
   g_signal_connect_swapped (priv->password_entry, "activate",
                             G_CALLBACK (confirm), page);
+  g_signal_connect (priv->reminder_entry, "notify::text",
+                      G_CALLBACK (reminder_changed), page);
 
   g_signal_connect (priv->confirm_entry, "notify::text",
                     G_CALLBACK (confirm_changed), page);
@@ -443,6 +461,7 @@ gis_password_page_class_init (GisPasswordPageClass *klass)
   gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisPasswordPage, 
password_strength);
   gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisPasswordPage, 
password_explanation);
   gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisPasswordPage, 
confirm_explanation);
+  gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisPasswordPage, reminder_entry);
   gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisPasswordPage, header);
 
   page_class->page_id = PAGE_ID;
diff --git a/gnome-initial-setup/pages/password/gis-password-page.ui 
b/gnome-initial-setup/pages/password/gis-password-page.ui
index b21010c4..cb991728 100644
--- a/gnome-initial-setup/pages/password/gis-password-page.ui
+++ b/gnome-initial-setup/pages/password/gis-password-page.ui
@@ -165,6 +165,52 @@
                 <property name="height">1</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkEntry" id="reminder_entry">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">10</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="reminder_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">1</property>
+                <property name="label" translatable="yes">Password _reminder</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">reminder_entry</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">10</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="reminder_explanation">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="yalign">0</property>
+                <property name="label" translatable="yes">Password reminder will be shown in case you forget 
your password.</property>
+                <property name="wrap">True</property>
+                <style>
+                  <class name="dim-label"/>
+                </style>
+                <attributes>
+                  <attribute name="scale" value="0.8"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">11</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
           </object>
         </child>
       </object>


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