From ca657cd018c2a3fab9c9742f416e1b01bc92db4d Mon Sep 17 00:00:00 2001 From: reionwong Date: Tue, 19 Oct 2021 20:02:46 +0800 Subject: [PATCH] User: Support change password --- src/qml/User/Main.qml | 5 +- src/qml/User/UserDelegateItem.qml | 95 ++++++++++++++++++++++++++++++- translations/en_US.ts | 23 +++++++- translations/zh_CN.ts | 25 +++++++- 4 files changed, 140 insertions(+), 8 deletions(-) diff --git a/src/qml/User/Main.qml b/src/qml/User/Main.qml index e01b882..8ef3729 100644 --- a/src/qml/User/Main.qml +++ b/src/qml/User/Main.qml @@ -43,8 +43,8 @@ ItemPage { onUserAdded: { if (account.userName === userNameField.text) { - account.passwordMode = UserAccount.RegularPasswordMode; - account.setPassword(Password.cryptPassword(passwordField.text)); + account.passwordMode = UserAccount.RegularPasswordMode + account.setPassword(Password.cryptPassword(passwordField.text)) } } } @@ -195,6 +195,7 @@ ItemPage { id: _addUserButton text: qsTr("Add user") Layout.fillWidth: true + visible: !newUserItem.visible onClicked: { newUserItem.visible = true userNameField.forceActiveFocus() diff --git a/src/qml/User/UserDelegateItem.qml b/src/qml/User/UserDelegateItem.qml index 40cd4fa..50a12ca 100644 --- a/src/qml/User/UserDelegateItem.qml +++ b/src/qml/User/UserDelegateItem.qml @@ -193,11 +193,87 @@ RoundedItem { } } + // Change password + HorizontalDivider { + visible: changePasswdLabel.visible + } + + Label { + id: changePasswdLabel + visible: false + text: qsTr("Change password") + } + + GridLayout { + id: changePasswdLayout + visible: false + columns: 2 + columnSpacing: FishUI.Units.largeSpacing * 2 + rowSpacing: FishUI.Units.smallSpacing * 2 + + Label { + text: qsTr("Password") + Layout.alignment: Qt.AlignRight + } + + TextField { + id: passwordField + placeholderText: qsTr("Password") + echoMode: TextField.Password + Layout.fillWidth: true + selectByMouse: true + } + + Label { + text: qsTr("Verify password") + Layout.alignment: Qt.AlignRight + } + + TextField { + id: verifyPasswordField + placeholderText: qsTr("Verify password") + echoMode: TextField.Password + Layout.fillWidth: true + selectByMouse: true + } + } + + RowLayout { + id: changePasswdFooterLayout + spacing: FishUI.Units.largeSpacing + visible: false + + Button { + text: qsTr("Cancel") + onClicked: hideChangePasswordItem() + Layout.fillWidth: true + } + + Button { + text: qsTr("Change password") + enabled: passwordField.text != "" && + passwordField.text == verifyPasswordField.text + Layout.fillWidth: true + flat: true + onClicked: { + currentUser.setPassword(Password.cryptPassword(passwordField.text)); + hideChangePasswordItem() + } + } + } + + HorizontalDivider { + visible: changePasswdLabel.visible + } + + // Change password end. + StandardButton { text: qsTr("Change password") - // onClicked: accountsManager.deleteUser(userId, true) + onClicked: showChangePasswordItem() backgroundColor: FishUI.Theme.darkMode ? "#363636" : FishUI.Theme.backgroundColor Layout.fillWidth: true + visible: !changePasswdLabel.visible } StandardButton { @@ -209,4 +285,21 @@ RoundedItem { } } } + + function showChangePasswordItem() { + changePasswdLabel.visible = true + changePasswdLayout.visible = true + changePasswdFooterLayout.visible = true + + passwordField.forceActiveFocus() + } + + function hideChangePasswordItem() { + passwordField.clear() + verifyPasswordField.clear() + + changePasswdLabel.visible = false + changePasswdLayout.visible = false + changePasswdFooterLayout.visible = false + } } diff --git a/translations/en_US.ts b/translations/en_US.ts index 96c0328..09f0229 100644 --- a/translations/en_US.ts +++ b/translations/en_US.ts @@ -761,12 +761,31 @@ - + + + Change password - + + + Password + Password + + + + + Verify password + Verify password + + + + Cancel + Cancel + + + Delete this user diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index 04776f8..8abe3f6 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -761,12 +761,31 @@ 自动登陆 - + + + Change password - + 更改密码 - + + + Password + 密码 + + + + + Verify password + 验证密码 + + + + Cancel + 取消 + + + Delete this user 删除该用户