Commit a2145046 authored by Julian Sparber's avatar Julian Sparber

accountsettings: password validation

* Show text when the new password doesn't match
* Disable apply button when not all entrys are filled

https://gitlab.gnome.org/World/fractal/issues/21
parent 8711c015
......@@ -122,7 +122,7 @@
</child>
<child>
<object class="GtkLabel" id="password-dialog-verify-hint">
<property name="visible">True</property>
<property name="visible">False</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="wrap">True</property>
......@@ -131,6 +131,7 @@
<property name="max_width_chars">35</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="label" translatable="yes">The passwords do not match.</property>
<attributes>
<attribute name="scale" value="0.82999999999999996"/>
</attributes>
......
......@@ -16,9 +16,18 @@ impl App {
let confirm = self.ui.builder
.get_object::<gtk::Button>("apply_account_settings")
.expect("Can't find join_room_button in ui file.");
let cancel_password = self.ui.builder
.get_object::<gtk::Button>("password-dialog-cancel")
.expect("Can't find password-dialog-cancel in ui file.");
let confirm_password = self.ui.builder
.get_object::<gtk::Button>("password-dialog-apply")
.expect("Can't find password-dialog-apply in ui file.");
let dialog = self.ui.builder
.get_object::<gtk::Dialog>("account_settings_dialog")
.expect("Can't find account_settings_dialog in ui file.");
let password_dialog = self.ui.builder
.get_object::<gtk::Dialog>("password_dialog")
.expect("Can't find password_dialog in ui file.");
let advanced_toggle = self.ui.builder
.get_object::<gtk::EventBox>("account_settings_advanced_toggle")
.expect("Can't find account_settings_advanced_toggle in ui file.");
......@@ -31,6 +40,15 @@ impl App {
let password_btn = self.ui.builder
.get_object::<gtk::Button>("account_settings_password")
.expect("Can't find account_settings_password in ui file.");
let old_password = self.ui.builder
.get_object::<gtk::Entry>("password-dialog-old-entry")
.expect("Can't find password-dialog-old-entry in ui file.");
let new_password = self.ui.builder
.get_object::<gtk::Entry>("password-dialog-entry")
.expect("Can't find password-dialog-entry in ui file.");
let verify_password = self.ui.builder
.get_object::<gtk::Entry>("password-dialog-verify-entry")
.expect("Can't find password-dialog-verify-entry in ui file.");
dialog.connect_delete_event(clone!(op => move |_, _| {
op.lock().unwrap().close_account_settings_dialog();
......@@ -58,17 +76,82 @@ impl App {
if let Some(file) = file_chooser.get_filename() {
if let Some(path) = file.to_str() {
op.lock().unwrap().save_tmp_avatar_account_settings(String::from(path));
}
}
}
}));
fn validate_password_input(builder: &gtk::Builder) {
let hint = builder
.get_object::<gtk::Label>("password-dialog-verify-hint")
.expect("Can't find password-dialog-verify-hint in ui file.");
let confirm_password = builder
.get_object::<gtk::Button>("password-dialog-apply")
.expect("Can't find password-dialog-apply in ui file.");
let old = builder
.get_object::<gtk::Entry>("password-dialog-old-entry")
.expect("Can't find password-dialog-old-entry in ui file.");
let new = builder
.get_object::<gtk::Entry>("password-dialog-entry")
.expect("Can't find password-dialog-entry in ui file.");
let verify = builder
.get_object::<gtk::Entry>("password-dialog-verify-entry")
.expect("Can't find password-dialog-verify-entry in ui file.");
let mut empty = true;
let mut matching = true;
if let Some(new) = new.get_text() {
if let Some(verify) = verify.get_text() {
if let Some(old) = old.get_text() {
if new != verify {
matching = false;
}
if new != "" && verify != "" && old != "" {
empty = false;
}
}
}
}
if matching {
hint.hide();
}
else {
hint.show();
}
confirm_password.set_sensitive(matching && !empty);
}
/* Passsword dialog */
password_btn.connect_clicked(clone!(op, builder => move |_| {
password_btn.connect_clicked(clone!(op => move |_| {
op.lock().unwrap().show_password_dialog();
}));
password_dialog.connect_delete_event(clone!(op => move |_, _| {
op.lock().unwrap().close_password_dialog();
glib::signal::Inhibit(true)
}));
/* Headerbar */
cancel_password.connect_clicked(clone!(op => move |_| {
op.lock().unwrap().close_password_dialog();
}));
confirm_password.connect_clicked(clone!(op => move |_| {
op.lock().unwrap().close_password_dialog();
}));
/* Body */
verify_password.connect_property_text_notify(clone!(op, builder => move |_| {
validate_password_input(&builder)
}));
new_password.connect_property_text_notify(clone!(op, builder => move |_| {
validate_password_input(&builder)
}));
old_password.connect_property_text_notify(clone!(op, builder => move |_| {
validate_password_input(&builder)
}));
advanced_toggle.connect_button_press_event(clone!(builder => move |this, _| {
let widget = builder
.get_object::<gtk::Revealer>("account_settings_advanced")
......
......@@ -57,6 +57,10 @@ impl AppOp {
let dialog = self.ui.builder
.get_object::<gtk::Dialog>("password_dialog")
.expect("Can't find password_dialog in ui file.");
let confirm_password = self.ui.builder
.get_object::<gtk::Button>("password-dialog-apply")
.expect("Can't find password-dialog-apply in ui file.");
confirm_password.set_sensitive(false);
dialog.present();
}
......@@ -117,4 +121,24 @@ impl AppOp {
dialog.hide();
dialog.resize(700, 200);
}
pub fn close_password_dialog(&mut self) {
let dialog = self.ui.builder
.get_object::<gtk::Dialog>("password_dialog")
.expect("Can't find password_dialog in ui file.");
let old_password = self.ui.builder
.get_object::<gtk::Entry>("password-dialog-old-entry")
.expect("Can't find password-dialog-old-entry in ui file.");
let new_password = self.ui.builder
.get_object::<gtk::Entry>("password-dialog-entry")
.expect("Can't find password-dialog-entry in ui file.");
let verify_password = self.ui.builder
.get_object::<gtk::Entry>("password-dialog-verify-entry")
.expect("Can't find password-dialog-verify-entry in ui file.");
/* Clear all user input */
old_password.set_text("");
new_password.set_text("");
verify_password.set_text("");
dialog.hide();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment