Module: Lich::Common::GUI::PasswordChange
- Defined in:
- documented/common/gui/password_change.rb
Class Method Summary collapse
-
.show_password_change_dialog(parent, data_dir, username) ⇒ void
Displays a dialog for changing the user’s password.
Class Method Details
.show_password_change_dialog(parent, data_dir, username) ⇒ void
This method returns an undefined value.
Displays a dialog for changing the user’s password.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'documented/common/gui/password_change.rb', line 16 def self.show_password_change_dialog(parent, data_dir, username) # Create dialog dialog = Gtk::Dialog.new( title: "Change Password", parent: parent, flags: :modal, buttons: [ ["Change Password", Gtk::ResponseType::APPLY], ["Cancel", Gtk::ResponseType::CANCEL] ] ) dialog.set_default_size(400, -1) dialog.border_width = 10 # Set accessible properties for screen readers Accessibility.make_window_accessible( dialog, "Password Change Dialog", "Dialog for changing account password" ) # Create content area content_area = dialog.content_area content_area.spacing = 10 # Add username label username_label = Gtk::Label.new username_label.set_markup("<span weight='bold'>Account:</span> #{username}") username_label.set_xalign(0) # Set accessible properties for screen readers Accessibility.make_accessible( username_label, "Account Username", "The username of the account being modified", :label ) content_area.add(username_label) # Add current password entry current_password_box = Gtk::Box.new(:horizontal, 5) current_password_label = Gtk::Label.new("Current Password:") current_password_label.set_xalign(0) current_password_box.pack_start(current_password_label, expand: false, fill: false, padding: 0) current_password_entry = Gtk::Entry.new current_password_entry.visibility = false # Set accessible properties for screen readers Accessibility.make_entry_accessible( current_password_entry, "Current Password Entry", "Enter your current account password" ) current_password_box.pack_start(current_password_entry, expand: true, fill: true, padding: 0) content_area.add(current_password_box) # Add new password entry new_password_box = Gtk::Box.new(:horizontal, 5) new_password_label = Gtk::Label.new("New Password:") new_password_label.set_xalign(0) new_password_box.pack_start(new_password_label, expand: false, fill: false, padding: 0) new_password_entry = Gtk::Entry.new new_password_entry.visibility = false # Set accessible properties for screen readers Accessibility.make_entry_accessible( new_password_entry, "New Password Entry", "Enter your new account password" ) new_password_box.pack_start(new_password_entry, expand: true, fill: true, padding: 0) content_area.add(new_password_box) # Add confirm password entry confirm_password_box = Gtk::Box.new(:horizontal, 5) confirm_password_label = Gtk::Label.new("Confirm Password:") confirm_password_label.set_xalign(0) confirm_password_box.pack_start(confirm_password_label, expand: false, fill: false, padding: 0) confirm_password_entry = Gtk::Entry.new confirm_password_entry.visibility = false # Set accessible properties for screen readers Accessibility.make_entry_accessible( confirm_password_entry, "Confirm Password Entry", "Confirm your new account password" ) confirm_password_box.pack_start(confirm_password_entry, expand: true, fill: true, padding: 0) content_area.add(confirm_password_box) # Add status label status_label = Gtk::Label.new("") status_label.set_xalign(0) # Set accessible properties for screen readers Accessibility.make_accessible( status_label, "Status Message", "Shows status messages during password change", :label ) content_area.add(status_label) # Show all widgets dialog.show_all # Set up response handler dialog.signal_connect('response') do |dlg, response| if response == Gtk::ResponseType::APPLY current_password = current_password_entry.text new_password = new_password_entry.text confirm_password = confirm_password_entry.text # Validate inputs if current_password.empty? status_label.set_markup("<span foreground='red'>Current password cannot be empty.</span>") next end if new_password.empty? status_label.set_markup("<span foreground='red'>New password cannot be empty.</span>") next end if new_password != confirm_password status_label.set_markup("<span foreground='red'>New passwords do not match.</span>") next end # Verify current password if verify_current_password(data_dir, username, current_password) # Change password if change_password(data_dir, username, new_password) # Show success message success_dialog = Gtk::MessageDialog.new( parent: parent, flags: :modal, type: :info, buttons: :ok, message: "Password changed successfully." ) # Set accessible properties for screen readers Accessibility.make_window_accessible( success_dialog, "Success Message", "Password change success notification" ) success_dialog.run success_dialog.destroy # Close dialog dlg.destroy else status_label.set_markup("<span foreground='red'>Failed to change password. Please try again.</span>") end else status_label.set_markup("<span foreground='red'>Current password is incorrect.</span>") end elsif response == Gtk::ResponseType::CANCEL dlg.destroy end end end |