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

@ -2,157 +2,61 @@
<interface> <interface>
<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="modal">True</property> <property name="default-height">300</property>
<child internal-child="content_area"> <property name="modal">True</property>
<object class="GtkBox"> <child type="titlebar">
<child> <object class="GtkHeaderBar">
<object class="GtkGrid" id="info_grid"> <property name="show-title-buttons">False</property>
<property name="orientation">vertical</property> <child>
<property name="margin-start">20</property> <object class="GtkButton" id="cancel_button">
<property name="margin-end">20</property> <property name="label" translatable="yes">Cancel</property>
<property name="margin-top">20</property> </object>
<property name="margin-bottom">20</property> </child>
<property name="row-spacing">7</property> <child type="end">
<property name="column-spacing">10</property> <object class="GtkButton" id="change_password_button">
<child> <property name="label" translatable="yes">Change</property>
<object class="GtkLabel"> <property name="sensitive">0</property>
<property name="label" translatable="1">Current password</property> <style>
<property name="xalign">1</property> <class name="suggested-action"/>
<layout> </style>
<property name="column">0</property> </object>
<property name="row">0</property> </child>
</layout> </object>
</object> </child>
</child> <child>
<child> <object class="AdwPreferencesPage">
<object class="GtkEntry" id="current_passwd_entry"> <child>
<property name="activates_default">1</property> <object class="AdwPreferencesGroup">
<property name="hexpand">1</property> <child>
<property name="width_request">200</property> <object class="AdwPasswordEntryRow" id="current_password_entry">
<property name="visibility">False</property> <property name="title" translatable="yes">Current password</property>
<layout> </object>
<property name="column">1</property> </child>
<property name="row">0</property> <child>
</layout> <object class="AdwPasswordEntryRow" id="new_password_entry">
</object> <property name="title" translatable="yes">New password</property>
</child> </object>
<child> </child>
<object class="GtkLabel"> <child>
<property name="label" translatable="1">New password</property> <object class="AdwPasswordEntryRow" id="confirm_new_password_entry">
<property name="xalign">1</property> <property name="title" translatable="yes">Confirm password</property>
<layout> </object>
<property name="column">0</property> </child>
<property name="row">1</property> <child>
</layout> <object class="GtkLabel" id="change_password_error_label">
</object> <property name="halign">center</property>
</child> <property name="hexpand">True</property>
<child> <property name="margin-top">7</property>
<object class="GtkEntry" id="new_passwd_entry"> <attributes>
<property name="activates_default">1</property> <attribute name="scale" value="0.9"></attribute>
<property name="hexpand">1</property> </attributes>
<property name="width_request">200</property> </object>
<property name="visibility">False</property> </child>
<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>
</child>
<child>
<object class="GtkLabel" id="change_password_error_label">
<!-- property name="xalign">0</property -->
<property name="halign">center</property>
<property name="hexpand">True</property>
<property name="margin-top">7</property>
<attributes>
<attribute name="scale" value="0.9"></attribute>
</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>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object> </object>
</child> </child>
<action-widgets> </object>
<action-widget response="cancel">cancel_button</action-widget> </child>
<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");