Change password inputs.

This commit is contained in:
Stanislav Malishevskiy 2024-04-03 15:40:15 +03:00
parent cd5e5db816
commit c5065c398c
4 changed files with 96 additions and 201 deletions

View file

@ -3,156 +3,60 @@
<requires lib="gtk" version="4.0"/> <requires lib="gtk" version="4.0"/>
<template class="DinoUiChangePasswordDialog"> <template class="DinoUiChangePasswordDialog">
<property name="title" translatable="1">Change password</property> <property name="title" translatable="1">Change password</property>
<property name="valign">center</property> <property name="default-width">350</property>
<property name="default-height">300</property>
<property name="modal">True</property> <property name="modal">True</property>
<child internal-child="content_area"> <child type="titlebar">
<object class="GtkBox"> <object class="GtkHeaderBar">
<property name="show-title-buttons">False</property>
<child> <child>
<object class="GtkGrid" id="info_grid"> <object class="GtkButton" id="cancel_button">
<property name="orientation">vertical</property> <property name="label" translatable="yes">Cancel</property>
<property name="margin-start">20</property> </object>
<property name="margin-end">20</property> </child>
<property name="margin-top">20</property> <child type="end">
<property name="margin-bottom">20</property> <object class="GtkButton" id="change_password_button">
<property name="row-spacing">7</property> <property name="label" translatable="yes">Change</property>
<property name="column-spacing">10</property> <property name="sensitive">0</property>
<child> <style>
<object class="GtkLabel"> <class name="suggested-action"/>
<property name="label" translatable="1">Current password</property> </style>
<property name="xalign">1</property> </object>
<layout> </child>
<property name="column">0</property>
<property name="row">0</property>
</layout>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkEntry" id="current_passwd_entry"> <object class="AdwPreferencesPage">
<property name="activates_default">1</property> <child>
<property name="hexpand">1</property> <object class="AdwPreferencesGroup">
<property name="width_request">200</property> <child>
<property name="visibility">False</property> <object class="AdwPasswordEntryRow" id="current_password_entry">
<layout> <property name="title" translatable="yes">Current password</property>
<property name="column">1</property>
<property name="row">0</property>
</layout>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkLabel"> <object class="AdwPasswordEntryRow" id="new_password_entry">
<property name="label" translatable="1">New password</property> <property name="title" translatable="yes">New password</property>
<property name="xalign">1</property>
<layout>
<property name="column">0</property>
<property name="row">1</property>
</layout>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkEntry" id="new_passwd_entry"> <object class="AdwPasswordEntryRow" id="confirm_new_password_entry">
<property name="activates_default">1</property> <property name="title" translatable="yes">Confirm password</property>
<property name="hexpand">1</property>
<property name="width_request">200</property>
<property name="visibility">False</property>
<layout>
<property name="column">1</property>
<property name="row">1</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="1">Confirm new password</property>
<property name="xalign">1</property>
<layout>
<property name="column">0</property>
<property name="row">2</property>
</layout>
</object>
</child>
<child>
<object class="GtkEntry" id="confirm_new_passwd_entry">
<property name="activates_default">1</property>
<property name="hexpand">1</property>
<property name="width_request">200</property>
<property name="visibility">False</property>
<layout>
<property name="column">1</property>
<property name="row">2</property>
</layout>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkLabel" id="change_password_error_label"> <object class="GtkLabel" id="change_password_error_label">
<!-- property name="xalign">0</property -->
<property name="halign">center</property> <property name="halign">center</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="margin-top">7</property> <property name="margin-top">7</property>
<attributes> <attributes>
<attribute name="scale" value="0.9"></attribute> <attribute name="scale" value="0.9"></attribute>
</attributes> </attributes>
<layout>
<property name="column">0</property>
<property name="row">3</property>
<property name="column-span">2</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton" id="cancel_button">
<property name="label" translatable="1">Cancel</property>
<layout>
<property name="column">0</property>
<property name="row">4</property>
</layout>
</object>
</child>
<child>
<object class="GtkButton" id="change_password_button">
<property name="halign">end</property>
<property name="hexpand">True</property>
<property name="sensitive">0</property>
<layout>
<property name="column">1</property>
<property name="row">4</property>
</layout>
<style>
<class name="text-button"/>
<class name="suggested-action"/>
</style>
<child>
<object class="GtkStack" id="change_password_stack">
<child>
<object class="GtkStackPage">
<property name="name">label</property>
<property name="child">
<object class="GtkLabel" >
<property name="label" translatable="1">Change password</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkStackPage">
<property name="name">spinner</property>
<property name="child">
<object class="GtkSpinner">
<property name="spinning">True</property>
</object>
</property>
</object> </object>
</child> </child>
</object> </object>
</child> </child>
</object> </object>
</child> </child>
</object>
</child>
</object>
</child>
<action-widgets>
<action-widget response="cancel">cancel_button</action-widget>
<action-widget response="ok" default="true">change_password_button</action-widget>
</action-widgets>
</template> </template>
</interface> </interface>

View file

@ -170,7 +170,7 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkButton" id="password_change_btn"> <object class="GtkButton" id="password_change_button">
<property name="label">⚙️</property> <property name="label">⚙️</property>
<layout> <layout>
<property name="column">2</property> <property name="column">2</property>

View file

@ -11,14 +11,13 @@ namespace Dino.Ui{
public class ChangePasswordDialog : Gtk.Dialog { public class ChangePasswordDialog : Gtk.Dialog {
[GtkChild] private unowned Button change_password_button; [GtkChild] private unowned Button change_password_button;
[GtkChild] private unowned Stack change_password_stack; /*[GtkChild] private unowned Stack change_password_stack; */
[GtkChild] private unowned Button cancel_button; [GtkChild] private unowned Button cancel_button;
[GtkChild] private unowned Entry current_passwd_entry; [GtkChild] private unowned Adw.PasswordEntryRow current_password_entry;
[GtkChild] private unowned Entry new_passwd_entry; [GtkChild] private unowned Adw.PasswordEntryRow new_password_entry;
[GtkChild] private unowned Entry confirm_new_passwd_entry; [GtkChild] private unowned Adw.PasswordEntryRow confirm_new_password_entry;
[GtkChild] private unowned Label change_password_error_label; [GtkChild] private unowned Label change_password_error_label;
private bool are_forms_empty;
private Account account; private Account account;
private StreamInteractor stream_interactor; private StreamInteractor stream_interactor;
@ -28,65 +27,57 @@ namespace Dino.Ui{
this.account = a; this.account = a;
Util.force_error_color(change_password_error_label); Util.force_error_color(change_password_error_label);
cancel_button.clicked.connect(() => { close(); }); cancel_button.clicked.connect(() => { close(); });
current_passwd_entry.changed.connect(on_current_passwd_entry_changed); current_password_entry.changed.connect(on_current_password_entry_changed);
new_passwd_entry.changed.connect(on_new_passwd_entry_changed); new_password_entry.changed.connect(on_new_password_entry_changed);
confirm_new_passwd_entry.changed.connect(on_confirm_new_passwd_entry_changed); confirm_new_password_entry.changed.connect(on_confirm_new_password_entry_changed);
change_password_button.clicked.connect(on_change_password_button_clicked); change_password_button.clicked.connect(on_change_password_button_clicked);
} }
private void are_psswd_nonempty(){ private void is_form_filled(){
EntryBuffer newpsswd = new_passwd_entry.get_buffer(); if (current_password_entry.get_text().length > 0
EntryBuffer confirm_newpsswd = confirm_new_passwd_entry.get_buffer(); && new_password_entry.get_text().length > 0
&& confirm_new_password_entry.get_text().length > 0
if (current_passwd_entry.get_text_length() > 0 && new_password_entry.get_text() == confirm_new_password_entry.get_text()){
&& new_passwd_entry.get_text_length() > 0
&& confirm_new_passwd_entry.get_text_length() > 0
&& newpsswd.get_text() == confirm_newpsswd.get_text()){
are_forms_empty = false;
change_password_button.sensitive = true; change_password_button.sensitive = true;
} else { } else {
are_forms_empty = true;
change_password_button.sensitive = false; change_password_button.sensitive = false;
} }
} }
private void check_new_passwd(){ private void check_new_password(){
EntryBuffer newpsswd = new_passwd_entry.get_buffer(); if (new_password_entry.get_text() != confirm_new_password_entry.get_text()){
EntryBuffer confirm_newpsswd = confirm_new_passwd_entry.get_buffer(); new_password_entry.add_css_class("error");
confirm_new_password_entry.add_css_class("error");
if (newpsswd.get_text() != confirm_newpsswd.get_text()){
new_passwd_entry.add_css_class("error");
confirm_new_passwd_entry.add_css_class("error");
} else { } else {
new_passwd_entry.remove_css_class("error"); new_password_entry.remove_css_class("error");
confirm_new_passwd_entry.remove_css_class("error"); confirm_new_password_entry.remove_css_class("error");
} }
} }
private void on_current_passwd_entry_changed(){ private void on_current_password_entry_changed(){
are_psswd_nonempty(); is_form_filled();
} }
private void on_new_passwd_entry_changed(){ private void on_new_password_entry_changed(){
are_psswd_nonempty(); is_form_filled();
check_new_passwd(); check_new_password();
} }
private void on_confirm_new_passwd_entry_changed(){ private void on_confirm_new_password_entry_changed(){
are_psswd_nonempty(); is_form_filled();
check_new_passwd(); check_new_password();
} }
private async void on_change_password_button_clicked(){ private async void on_change_password_button_clicked(){
string? pw_input = current_passwd_entry.get_buffer().get_text(); string? pw_input = current_password_entry.get_text();
string? new_pw_input = new_passwd_entry.get_buffer().get_text(); string? new_pw_input = new_password_entry.get_text();
if (pw_input != null && account.password == pw_input){ if (pw_input != null && account.password == pw_input){
change_password_button.sensitive = false; change_password_button.sensitive = false;
change_password_stack.visible_child_name = "spinner"; // change_password_stack.visible_child_name = "spinner";
string ret = yield stream_interactor.get_module(Register.IDENTITY).change_password(account, new_pw_input); string ret = yield stream_interactor.get_module(Register.IDENTITY).change_password(account, new_pw_input);
change_password_button.sensitive = true; change_password_button.sensitive = true;
change_password_stack.visible_child_name = "label"; // change_password_stack.visible_child_name = "label";
if (ret == null) { if (ret == null) {
account.password = new_pw_input; account.password = new_pw_input;
close(); close();

View file

@ -25,7 +25,7 @@ public class Dialog : Gtk.Dialog {
[GtkChild] public unowned Label state_label; [GtkChild] public unowned Label state_label;
[GtkChild] public unowned Switch active_switch; [GtkChild] public unowned Switch active_switch;
[GtkChild] public unowned Util.EntryLabelHybrid password_hybrid; [GtkChild] public unowned Util.EntryLabelHybrid password_hybrid;
[GtkChild] public unowned Button password_change_btn; [GtkChild] public unowned Button password_change_button;
[GtkChild] public unowned Util.EntryLabelHybrid alias_hybrid; [GtkChild] public unowned Util.EntryLabelHybrid alias_hybrid;
[GtkChild] public unowned Grid settings_list; [GtkChild] public unowned Grid settings_list;
@ -45,12 +45,12 @@ public class Dialog : Gtk.Dialog {
image_button.clicked.connect(show_select_avatar); image_button.clicked.connect(show_select_avatar);
alias_hybrid.entry.changed.connect(() => { selected_account.alias = alias_hybrid.text; }); alias_hybrid.entry.changed.connect(() => { selected_account.alias = alias_hybrid.text; });
password_hybrid.entry.changed.connect(() => { selected_account.password = password_hybrid.text; }); password_hybrid.entry.changed.connect(() => { selected_account.password = password_hybrid.text; });
password_change_btn.clicked.connect(show_change_psswd_dialog); password_change_button.clicked.connect(show_change_password_dialog);
Util.LabelHybridGroup label_hybrid_group = new Util.LabelHybridGroup(); Util.LabelHybridGroup label_hybrid_group = new Util.LabelHybridGroup();
label_hybrid_group.add(alias_hybrid); label_hybrid_group.add(alias_hybrid);
label_hybrid_group.add(password_hybrid); label_hybrid_group.add(password_hybrid);
password_change_btn.sensitive = false; password_change_button.sensitive = false;
main_stack.set_visible_child_name("no_accounts"); main_stack.set_visible_child_name("no_accounts");
@ -112,10 +112,10 @@ public class Dialog : Gtk.Dialog {
add_account_dialog.present(); add_account_dialog.present();
} }
private void show_change_psswd_dialog() { private void show_change_password_dialog() {
ChangePasswordDialog change_psswd_dialog = new ChangePasswordDialog(selected_account, stream_interactor); ChangePasswordDialog change_password_dialog = new ChangePasswordDialog(selected_account, stream_interactor);
change_psswd_dialog.set_transient_for(this); change_password_dialog.set_transient_for(this);
change_psswd_dialog.present(); change_password_dialog.present();
} }
// //
private void remove_account(AccountRow account_item) { private void remove_account(AccountRow account_item) {
@ -224,10 +224,10 @@ public class Dialog : Gtk.Dialog {
case ConnectionManager.ConnectionState.CONNECTING: case ConnectionManager.ConnectionState.CONNECTING:
state_label.label = _("Connecting…"); break; state_label.label = _("Connecting…"); break;
case ConnectionManager.ConnectionState.CONNECTED: case ConnectionManager.ConnectionState.CONNECTED:
password_change_btn.sensitive = true; password_change_button.sensitive = true;
state_label.label = _("Connected"); break; state_label.label = _("Connected"); break;
case ConnectionManager.ConnectionState.DISCONNECTED: case ConnectionManager.ConnectionState.DISCONNECTED:
password_change_btn.sensitive = false; password_change_button.sensitive = false;
state_label.label = _("Disconnected"); break; state_label.label = _("Disconnected"); break;
} }
state_label.remove_css_class("is_error"); state_label.remove_css_class("is_error");
@ -235,7 +235,7 @@ public class Dialog : Gtk.Dialog {
} }
private string get_connection_error_description(ConnectionManager.ConnectionError error) { private string get_connection_error_description(ConnectionManager.ConnectionError error) {
password_change_btn.sensitive = false; password_change_button.sensitive = false;
switch (error.source) { switch (error.source) {
case ConnectionManager.ConnectionError.Source.SASL: case ConnectionManager.ConnectionError.Source.SASL:
return _("Wrong password"); return _("Wrong password");