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"/>
<template class="DinoUiChangePasswordDialog">
<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>
<child internal-child="content_area">
<object class="GtkBox">
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="show-title-buttons">False</property>
<child>
<object class="GtkGrid" id="info_grid">
<property name="orientation">vertical</property>
<property name="margin-start">20</property>
<property name="margin-end">20</property>
<property name="margin-top">20</property>
<property name="margin-bottom">20</property>
<property name="row-spacing">7</property>
<property name="column-spacing">10</property>
<child>
<object class="GtkLabel">
<property name="label" translatable="1">Current password</property>
<property name="xalign">1</property>
<layout>
<property name="column">0</property>
<property name="row">0</property>
</layout>
<object class="GtkButton" id="cancel_button">
<property name="label" translatable="yes">Cancel</property>
</object>
</child>
<child type="end">
<object class="GtkButton" id="change_password_button">
<property name="label" translatable="yes">Change</property>
<property name="sensitive">0</property>
<style>
<class name="suggested-action"/>
</style>
</object>
</child>
</object>
</child>
<child>
<object class="GtkEntry" id="current_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">0</property>
</layout>
<object class="AdwPreferencesPage">
<child>
<object class="AdwPreferencesGroup">
<child>
<object class="AdwPasswordEntryRow" id="current_password_entry">
<property name="title" translatable="yes">Current password</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="1">New password</property>
<property name="xalign">1</property>
<layout>
<property name="column">0</property>
<property name="row">1</property>
</layout>
<object class="AdwPasswordEntryRow" id="new_password_entry">
<property name="title" translatable="yes">New password</property>
</object>
</child>
<child>
<object class="GtkEntry" id="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">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 class="AdwPasswordEntryRow" id="confirm_new_password_entry">
<property name="title" translatable="yes">Confirm password</property>
</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>
</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>
</interface>

View file

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

View file

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

View file

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