Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update change password #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Change password inputs.
smalishevskiy committed Apr 19, 2024
commit c5065c398ca2d0aa4e0ed35adf7ad8f93fcae2ca
206 changes: 55 additions & 151 deletions main/data/manage_accounts/change_password_dialog.ui
Original file line number Diff line number Diff line change
@@ -2,157 +2,61 @@
<interface>
<requires lib="gtk" version="4.0"/>
<template class="DinoUiChangePasswordDialog">
<property name="title" translatable="1">Change password</property>
<property name="valign">center</property>
<property name="modal">True</property>
<child internal-child="content_area">
<object class="GtkBox">
<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>
</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>
</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>
</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>
</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>
<property name="title" translatable="1">Change password</property>
<property name="default-width">350</property>
<property name="default-height">300</property>
<property name="modal">True</property>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="show-title-buttons">False</property>
<child>
<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="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="AdwPasswordEntryRow" id="new_password_entry">
<property name="title" translatable="yes">New password</property>
</object>
</child>
<child>
<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="halign">center</property>
<property name="hexpand">True</property>
<property name="margin-top">7</property>
<attributes>
<attribute name="scale" value="0.9"></attribute>
</attributes>
</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>
</child>
</object>
</child>
</template>
</interface>
2 changes: 1 addition & 1 deletion main/data/manage_accounts/dialog.ui
Original file line number Diff line number Diff line change
@@ -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>
69 changes: 30 additions & 39 deletions main/src/ui/manage_accounts/change_password_dialog.vala
Original file line number Diff line number Diff line change
@@ -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();
Loading