diff --git a/libdino/src/service/registration.vala b/libdino/src/service/registration.vala index 4255f322..853a2994 100644 --- a/libdino/src/service/registration.vala +++ b/libdino/src/service/registration.vala @@ -71,6 +71,12 @@ public class Register : StreamInteractionModule, Object{ return ret; } + public async void change_password(Account account, string new_pw){ + XmppStream stream = stream_interactor.get_stream(account); + if (stream == null) return; + yield stream.get_module(Xep.InBandRegistration.Module.IDENTITY).change_password(stream, account.full_jid, new_pw); + } + public class ServerAvailabilityReturn { public bool available { get; set; } public TlsCertificateFlags? error_flags { get; set; } diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index ea4de99b..13988c87 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -78,6 +78,7 @@ set(RESOURCE_LIST conversation_content_view/view.ui manage_accounts/account_row.ui manage_accounts/add_account_dialog.ui + manage_accounts/change_password_dialog.ui manage_accounts/dialog.ui menu_add.ui menu_app.ui @@ -217,6 +218,7 @@ SOURCES src/ui/manage_accounts/account_row.vala src/ui/manage_accounts/add_account_dialog.vala + src/ui/manage_accounts/change_password_dialog.vala src/ui/manage_accounts/dialog.vala src/ui/occupant_menu/list.vala diff --git a/main/data/gresource.xml b/main/data/gresource.xml index 282838e0..a2e3f047 100644 --- a/main/data/gresource.xml +++ b/main/data/gresource.xml @@ -58,6 +58,7 @@ manage_accounts/account_row.ui manage_accounts/add_account_dialog.ui manage_accounts/dialog.ui + manage_accounts/change_password_dialog.ui menu_add.ui menu_app.ui menu_conversation.ui diff --git a/main/data/manage_accounts/change_password_dialog.ui b/main/data/manage_accounts/change_password_dialog.ui new file mode 100644 index 00000000..df670d78 --- /dev/null +++ b/main/data/manage_accounts/change_password_dialog.ui @@ -0,0 +1,113 @@ + + + + + diff --git a/main/data/manage_accounts/dialog.ui b/main/data/manage_accounts/dialog.ui index 4931507c..0a76c361 100644 --- a/main/data/manage_accounts/dialog.ui +++ b/main/data/manage_accounts/dialog.ui @@ -165,7 +165,17 @@ 1 2 - 2 + 1 + + + + + + ⚙️ + + 2 + 2 + 1 diff --git a/main/meson.build b/main/meson.build index 1b5abcfc..ee17404c 100644 --- a/main/meson.build +++ b/main/meson.build @@ -71,6 +71,7 @@ sources = files( 'src/ui/main_window_controller.vala', 'src/ui/manage_accounts/account_row.vala', 'src/ui/manage_accounts/add_account_dialog.vala', + 'src/ui/manage_accounts/change_password_dialog.vala', 'src/ui/manage_accounts/dialog.vala', 'src/ui/notifier_freedesktop.vala', 'src/ui/notifier_gnotifications.vala', diff --git a/main/src/ui/manage_accounts/change_password_dialog.vala b/main/src/ui/manage_accounts/change_password_dialog.vala new file mode 100644 index 00000000..2c6db522 --- /dev/null +++ b/main/src/ui/manage_accounts/change_password_dialog.vala @@ -0,0 +1,77 @@ +using Gee; +using Gtk; +//using Pango; + +using Dino.Entities; +using Xmpp; + +namespace Dino.Ui{ + +[GtkTemplate (ui = "/im/dino/Dino/manage_accounts/change_password_dialog.ui")] + public class ChangePasswordDialog : Gtk.Dialog { + + [GtkChild] private unowned Button ok_button; + [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; + private bool are_forms_empty; + private Account account; + private StreamInteractor stream_interactor; + + public ChangePasswordDialog(Account a, StreamInteractor s){ + Object(use_header_bar : 1); + this.stream_interactor = s; + this.account = a; + 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); + ok_button.clicked.connect(on_ok_button_clicked); + } + + private void are_psswd_nonempty(){ + if (current_passwd_entry.get_text_length() > 0 && new_passwd_entry.get_text_length() > 0 && confirm_new_passwd_entry.get_text_length() > 0){ + are_forms_empty = false; + ok_button.sensitive = true; + } else { + are_forms_empty = true; + ok_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"); + } else { + new_passwd_entry.remove_css_class("error"); + } + } + + private void on_current_passwd_entry_changed(){ + are_psswd_nonempty(); + } + + private void on_new_passwd_entry_changed(){ + are_psswd_nonempty(); + check_new_passwd(); + } + + private void on_confirm_new_passwd_entry_changed(){ + are_psswd_nonempty(); + check_new_passwd(); + } + + private async void on_ok_button_clicked(){ + string? pw_input = current_passwd_entry.get_buffer().get_text(); + string? new_pw_input = new_passwd_entry.get_buffer().get_text(); + if(pw_input != null && account.password == pw_input){ + stream_interactor.get_module(Register.IDENTITY).change_password.begin(account, new_pw_input); +// close(); + } + } + } +} diff --git a/main/src/ui/manage_accounts/dialog.vala b/main/src/ui/manage_accounts/dialog.vala index a326aeff..365d4c3c 100644 --- a/main/src/ui/manage_accounts/dialog.vala +++ b/main/src/ui/manage_accounts/dialog.vala @@ -25,6 +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 Util.EntryLabelHybrid alias_hybrid; [GtkChild] public unowned Grid settings_list; @@ -44,10 +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); 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; main_stack.set_visible_child_name("no_accounts"); @@ -109,6 +112,12 @@ 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 remove_account(AccountRow account_item) { Gtk.MessageDialog msg = new Gtk.MessageDialog ( this, Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL, @@ -215,8 +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; state_label.label = _("Connected"); break; case ConnectionManager.ConnectionState.DISCONNECTED: + password_change_btn.sensitive = false; state_label.label = _("Disconnected"); break; } state_label.remove_css_class("is_error"); @@ -224,6 +235,7 @@ public class Dialog : Gtk.Dialog { } private string get_connection_error_description(ConnectionManager.ConnectionError error) { + password_change_btn.sensitive = false; switch (error.source) { case ConnectionManager.ConnectionError.Source.SASL: return _("Wrong password"); diff --git a/xmpp-vala/src/module/xep/0077_in_band_registration.vala b/xmpp-vala/src/module/xep/0077_in_band_registration.vala index baaa4ee0..89a31c3c 100644 --- a/xmpp-vala/src/module/xep/0077_in_band_registration.vala +++ b/xmpp-vala/src/module/xep/0077_in_band_registration.vala @@ -29,6 +29,30 @@ public class Module : XmppStreamNegotiationModule { return null; } + + public async void change_password(XmppStream stream, Jid jid, string new_pw) { + StanzaNode pw_change_node = new StanzaNode.build("query",NS_URI).add_self_xmlns(); + StanzaNode username_node = new StanzaNode.build("username"); + StanzaNode pw_node = new StanzaNode.build("password"); + username_node.put_node(new StanzaNode.text(jid.localpart)); + pw_node.put_node(new StanzaNode.text(new_pw)); + pw_change_node.put_node(username_node); + pw_change_node.put_node(pw_node); + //pw_change_node.put_node(new StanzaNode.build()); +// StanzaNode execute_chpw = new StanzaNode.build("command","http://jabber.org/protocol/commands").add_self_xmlns(); +// execute_chpw.put_attribute("node","passwd"); +// execute_chpw.put_attribute("action","execute"); + Iq.Stanza set_password_iq = new Iq.Stanza.set(pw_change_node, "changepwtest") { to=jid.bare_jid.domain_jid }; + +// Iq.Stanza set_password_iq = new Iq.Stanza.set(execute_chpw) { to=jid.bare_jid.domain_jid }; + Iq.Stanza chpw_result = yield stream.get_module(Iq.Module.IDENTITY).send_iq_async(stream, set_password_iq); + if (chpw_result.is_error()) { + ErrorStanza? error_stanza = chpw_result.get_error(); + stderr.printf("\n" + error_stanza.text ?? "Error when trying to change password \n"); + } +// StanzaNode changepw_node = new StanzaNode.build("query", NS_URI).add_self_xmlns(); + + } public override bool mandatory_outstanding(XmppStream stream) { return false; }