[gnome-control-center/T20818: 36/54] user-accounts: Allow to change the password mode for oneself



commit 814fbb57ab0b65453688eef0475d26fefe0dd005
Author: Joaquim Rocha <jrocha endlessm com>
Date:   Mon Jun 12 13:06:00 2017 +0200

    user-accounts: Allow to change the password mode for oneself
    
    This patch modifies the password change dialog in order to allow users
    to change their own password mode (i.e. remove or reinstate a password).
    
    Unlike when changing the password for other users, when changing it for
    oneself, if a password is currently set, the password change dialog will
    require the user to authenticate before modifying the mode or password.
    
    https://phabricator.endlessm.com/T17270

 panels/user-accounts/data/password-dialog.ui |   11 ++++-------
 panels/user-accounts/um-password-dialog.c    |   17 +++++++++++------
 2 files changed, 15 insertions(+), 13 deletions(-)
---
diff --git a/panels/user-accounts/data/password-dialog.ui b/panels/user-accounts/data/password-dialog.ui
index 984f94a..6853c0f 100644
--- a/panels/user-accounts/data/password-dialog.ui
+++ b/panels/user-accounts/data/password-dialog.ui
@@ -210,13 +210,10 @@
                     <property name="mnemonic_widget">old-password-entry</property>
                     <property name="margin_start">25</property>
                     <property name="margin_bottom">12</property>
-                    <style>
-                      <class name="dim-label"/>
-                    </style>
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">3</property>
+                    <property name="top_attach">1</property>
                   </packing>
                 </child>
                 <child>
@@ -231,7 +228,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
-                    <property name="top_attach">3</property>
+                    <property name="top_attach">1</property>
                   </packing>
                 </child>
                 <child>
@@ -253,7 +250,7 @@
                     </child>
                     <child>
                       <object class="GtkRadioButton" id="action-no-password-radio">
-                        <property name="label" translatable="yes">Allow user to log in without a 
password</property>
+                        <property name="label" translatable="yes">Do not require a password when logging 
in</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">False</property>
@@ -282,7 +279,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">1</property>
+                    <property name="top_attach">3</property>
                     <property name="width">3</property>
                   </packing>
                 </child>
diff --git a/panels/user-accounts/um-password-dialog.c b/panels/user-accounts/um-password-dialog.c
index dcddc48..225cf99 100644
--- a/panels/user-accounts/um-password-dialog.c
+++ b/panels/user-accounts/um-password-dialog.c
@@ -242,7 +242,7 @@ static void
 update_sensitivity (UmPasswordDialog *um)
 {
         const gchar *password, *verify;
-        gboolean can_change;
+        gboolean can_change = TRUE;
 
         password = gtk_entry_get_text (GTK_ENTRY (um->password_entry));
         verify = gtk_entry_get_text (GTK_ENTRY (um->verify_entry));
@@ -252,8 +252,8 @@ update_sensitivity (UmPasswordDialog *um)
                 can_change = password && password[0] != '\0' && strcmp (password, verify) == 0 &&
                              (um->old_password_ok || !gtk_widget_get_visible (um->old_password_entry));
         }
-        else {
-                can_change = TRUE;
+        else if (um->password_mode == ACT_USER_PASSWORD_MODE_NONE) {
+                can_change = um->old_password_ok || !gtk_widget_get_visible (um->old_password_entry);
         }
 
         gtk_widget_set_sensitive (um->ok_button, can_change);
@@ -264,11 +264,11 @@ mode_change (UmPasswordDialog *um,
              ActUserPasswordMode mode)
 {
         gboolean active;
+        gboolean user_is_self = (act_user_get_uid (um->user) == getuid ());
 
         active = (mode == ACT_USER_PASSWORD_MODE_REGULAR);
         gtk_widget_set_sensitive (um->password_entry, active);
         gtk_widget_set_sensitive (um->verify_entry, active);
-        gtk_widget_set_sensitive (um->old_password_entry, active);
         gtk_widget_set_sensitive (um->password_hint, active);
         gtk_widget_set_sensitive (um->password_reminder, active);
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (um->action_now_radio), active);
@@ -277,6 +277,11 @@ mode_change (UmPasswordDialog *um,
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (um->action_no_password_radio),
                                       (mode == ACT_USER_PASSWORD_MODE_NONE));
 
+        if (user_is_self) {
+                gtk_widget_set_sensitive (um->old_password_entry,
+                                          act_user_get_password_mode (um->user) == 
ACT_USER_PASSWORD_MODE_REGULAR);
+        }
+
         um->password_mode = mode;
         update_sensitivity (um);
 }
@@ -606,12 +611,13 @@ um_password_dialog_set_user (UmPasswordDialog *um,
 
                 gtk_entry_set_visibility (GTK_ENTRY (um->password_entry), FALSE);
                 gtk_entry_set_visibility (GTK_ENTRY (um->verify_entry), FALSE);
+                gtk_widget_show_all (um->action_radio_box);
 
                 if (act_user_get_uid (um->user) == getuid ()) {
                         mode_change (um, ACT_USER_PASSWORD_MODE_REGULAR);
-                        gtk_widget_hide (um->action_radio_box);
 
                         visible = (act_user_get_password_mode (user) != ACT_USER_PASSWORD_MODE_NONE);
+                        gtk_widget_hide (um->action_login_radio);
                         gtk_widget_set_visible (um->old_password_label, visible);
                         gtk_widget_set_visible (um->old_password_entry, visible);
                         gtk_entry_set_text (GTK_ENTRY (um->password_reminder), act_user_get_password_hint 
(user));
@@ -619,7 +625,6 @@ um_password_dialog_set_user (UmPasswordDialog *um,
                 }
                 else {
                         mode_change (um, act_user_get_password_mode (user));
-                        gtk_widget_show (um->action_radio_box);
 
                         gtk_widget_hide (um->old_password_label);
                         gtk_widget_hide (um->old_password_entry);


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