feat(desktop/profile) adding password changed modal

Implemented new change password succcess confirmation
popup

Closes #3432
This commit is contained in:
Alexandra Betouni 2021-09-09 17:04:05 +03:00 committed by Iuri Matias
parent d3c9564d91
commit 22994a4a14
4 changed files with 126 additions and 82 deletions

View File

@ -10,7 +10,7 @@ import status/status
import status/ens as status_ens
import status/chat/chat
import status/types/[setting, os_notification]
import status/constants as accountConstants
import ../../constants
import status/notifications/[os_notifications]
import ../../app_service/[main]
import qrcode/qrcode
@ -126,9 +126,16 @@ QtObject:
read = getEnsManager
proc changePassword(self: ProfileView, password: string, newPassword: string): bool {.slot.} =
let
defaultAccount = status_accounts.getDefaultAccount()
isPasswordOk = status_accounts.verifyAccountPassword(defaultAccount, password, KEYSTOREDIR)
if not isPasswordOk:
return false
if self.status.accounts.changePassword(self.profile.address, password, newPassword):
quit(QuitSuccess) # quits the app TODO: change this to logout instead when supported
return false
return true
else:
return false
proc getLinkPreviewWhitelist*(self: ProfileView): string {.slot.} =
result = $(self.status.profile.getLinkPreviewWhitelist())
@ -205,4 +212,4 @@ QtObject:
)
self.appService.osNotificationService.showNotification(title, message,
details, useOSNotifications)
details, useOSNotifications)

View File

@ -1,103 +1,102 @@
import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.12
import StatusQ.Controls 0.1
import "../../../../imports"
import "../../../../shared"
ModalPopup {
import StatusQ.Popups 0.1
import StatusQ.Controls 0.1
StatusModal {
id: popup
title: qsTr("Change password")
width: 480
height: 510
closePolicy: Popup.NoAutoClose
header.title: qsTr("Change password")
onOpened: {
reset()
reset();
}
property bool loading: false
property bool firstPasswordFieldValid: false
property bool repeatPasswordFieldValid: false
property string passwordValidationError: ""
property string repeatPasswordValidationError: ""
property string changePasswordError: ""
property var successPopup
property string indicationText: ""
property bool passwordInputValid
property bool currPasswordInputValid
property string currPasswordValidationError: ""
function reset() {
currentPasswordField.text = ""
firstPasswordField.text = ""
repeatPasswordField.text = ""
currentPasswordField.forceActiveFocus(Qt.MouseFocusReason)
firstPasswordFieldValid = false
repeatPasswordFieldValid = false
passwordValidationError = ""
repeatPasswordValidationError = ""
changePasswordError = ""
loading = false
passwordInput.text = "";
currentPasswordInput.text = "";
currentPasswordInput.forceActiveFocus(Qt.MouseFocusReason);
popup.indicationText = "At least 6 characters. Your password protects your keys. You need it to unlock Status and transact.";
popup.currPasswordValidationError = "";
passwordInput.validationError = "";
popup.passwordInputValid = false;
popup.currPasswordInputValid = false;
}
ColumnLayout {
contentItem: ColumnLayout {
id: contentItem
anchors.fill: parent
anchors.margins: Style.current.xlPadding
spacing: Style.current.xlPadding
anchors {
topMargin: (Style.current.xlPadding + popup.topPadding)
leftMargin: Style.current.xlPadding
rightMargin: Style.current.xlPadding
bottomMargin: (Style.current.xlPadding + popup.bottomPadding)
}
spacing: Style.current.padding
//TODO replace with StatusInput as soon as it supports password
Input {
id: currentPasswordField
id: currentPasswordInput
anchors.left: undefined
anchors.right: undefined
Layout.fillWidth: true
placeholderText: qsTr("Current password")
placeholderText: ""
label: qsTr("Current password")
textField.echoMode: TextInput.Password
onTextChanged: {
changePasswordError = ""
popup.currPasswordInputValid = (currentPasswordInput.text.length >= 6);
}
}
//TODO replace with StatusInput as soon as it supports password
Input {
id: firstPasswordField
id: passwordInput
anchors.left: undefined
anchors.right: undefined
Layout.fillWidth: true
//% "New password..."
placeholderText: qsTrId("new-password...")
placeholderText: ""
label: qsTrId("new-password...")
textField.echoMode: TextInput.Password
onTextChanged: {
[firstPasswordFieldValid, passwordValidationError] =
Utils.validatePasswords("first", firstPasswordField, repeatPasswordField);
popup.passwordInputValid = ((passwordInput.text !== "") && (passwordInput.text.length >= 6));
//setting validationError so that input becomes red
passwordInput.validationError = (!popup.passwordInputValid) ? " " : "";
popup.indicationText = (!popup.passwordInputValid ? "<font color=\"#FF2D55\">" : "")
+ "At least 6 characters." + (!popup.passwordInputValid ? "</font>" : "")
+ "Your password protects your keys. You need it to unlock Status and transact."
}
}
Input {
id: repeatPasswordField
anchors.left: undefined
anchors.right: undefined
Layout.fillWidth: true
enabled: firstPasswordFieldValid
//% "Confirm password"
placeholderText: qsTrId("confirm-password…")
textField.echoMode: TextInput.Password
Keys.onReturnPressed: function(event) {
if (submitBtn.enabled) {
submitBtn.clicked(event)
}
}
onTextChanged: {
[repeatPasswordFieldValid, repeatPasswordValidationError] =
Utils.validatePasswords("repeat", firstPasswordField, repeatPasswordField);
}
Item {
Layout.fillHeight: true
}
StyledText {
id: validationError
text: passwordValidationError || repeatPasswordValidationError || changePasswordError
Layout.preferredWidth: 340
Layout.preferredWidth: parent.width
Layout.alignment: Qt.AlignHCenter
horizontalAlignment: Text.AlignHCenter
color: Style.current.danger
visible: (text !== "")
font.pixelSize: Style.current.tertiaryTextFontSize
color: Style.current.danger
text: popup.currPasswordValidationError
}
StyledText {
text: qsTr("Status app will be terminated after password change. You need to restart it to login using the new password.")
text: qsTr(indicationText)
wrapMode: Text.WordWrap
Layout.preferredWidth: 340
Layout.alignment: Qt.AlignHCenter
@ -107,26 +106,39 @@ ModalPopup {
}
}
footer: Item {
width: parent.width
height: submitBtn.height
rightButtons: [
StatusButton {
id: submitBtn
anchors.right: parent.right
text: qsTr("Change password")
enabled: popup.firstPasswordFieldValid && popup.repeatPasswordFieldValid && !popup.loading
state: popup.loading ? "pending" : "default"
enabled: (popup.passwordInputValid && popup.currPasswordInputValid && !submitBtn.loading)
onClicked: {
popup.loading = true
if (profileModel.changePassword(currentPasswordField.text, firstPasswordField.text)) {
popup.close()
} else {
reset()
changePasswordError = qsTr("Failed to change password.")
property Timer sim: Timer {
id: pause
interval: 20
onTriggered: {
submitBtn.changePasswordBegin();
}
}
onClicked: {
submitBtn.loading = true;
//changePassword operation blocks the UI so loading = true; will never
//have any affect until changePassword is done. Getting around it with a
//small pause (timer) in order to get the desired behavior
pause.start();
}
function changePasswordBegin() {
if (profileModel.changePassword(currentPasswordInput.text, passwordInput.text)) {
popup.successPopup.open();
submitBtn.enabled = false;
} else {
reset();
passwordInput.validationError = " ";
popup.currPasswordValidationError = qsTr("Incorrect password");
}
submitBtn.loading = false;
}
}
}
]
}

View File

@ -1,32 +1,50 @@
import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.12
import StatusQ.Controls 0.1
import "../../../../imports"
import "../../../../shared"
ModalPopup {
import StatusQ.Core 0.1
import StatusQ.Popups 0.1
import StatusQ.Controls 0.1
import StatusQ.Core.Theme 0.1
StatusModal {
id: root
width: 400
height: 248
closePolicy: Popup.NoAutoClose
contentItem: Column {
implicitWidth: root.width
implicitHeight: root.height
spacing: 8
showHeader: false
contentItem: ColumnLayout {
anchors.fill: parent
anchors.margins: 45
spacing: Style.current.halfPadding
StatusIcon {
icon: "check"
Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: 26
Layout.preferredHeight: 26
icon: "checkmark"
color: Style.current.green
}
StatusBaseText {
Layout.alignment: Qt.AlignHCenter
font.pixelSize: 18
text: qsTr("<b>Password changed</b>")
}
StatusBaseText {
Layout.alignment: Qt.AlignHCenter
font.pixelSize: 13
color: Theme.palette.baseColor1
text: qsTr("You need to sign in again using the new password.")
}
StatusButton {
id: submitBtn
anchors.right: parent.right
text: qsTr("Log out")
Layout.alignment: Qt.AlignHCenter
text: qsTr("Sign out & Quit")
onClicked: {
//quits the app TODO: change this to logout instead when supported
Qt.quit();

View File

@ -51,6 +51,13 @@ Item {
ChangePasswordModal {
id: changePasswordModal
anchors.centerIn: parent
successPopup: successPopup
}
ChangePasswordSuccessModal {
id: successPopup
anchors.centerIn: parent
}
Item {