2022-03-01 15:59:38 +00:00
import QtQuick 2.0
import QtQuick . Controls 2.13
import QtQuick . Layouts 1.12
2022-03-23 19:51:39 +00:00
import QtQuick . Dialogs 1.3
2022-03-01 15:59:38 +00:00
import shared . controls 1.0
import shared 1.0
import shared . panels 1.0
import utils 1.0
import StatusQ . Controls 0.1
import StatusQ . Core 0.1
import StatusQ . Core . Theme 0.1
import "../stores"
2022-03-07 22:59:38 +00:00
import "../controls"
2022-03-01 15:59:38 +00:00
2022-03-07 22:59:38 +00:00
OnboardingBasePage {
2022-03-01 15:59:38 +00:00
id: root
property string password
2022-03-07 22:59:38 +00:00
property string tmpPass
property string displayName
function forcePswInputFocus ( ) { confPswInput . forceActiveFocus ( Qt . MouseFocusReason ) }
2022-03-01 15:59:38 +00:00
Column {
id: view
spacing: 4 * Style . current . padding
width: 416
anchors.centerIn: parent
StatusBaseText {
anchors.horizontalCenter: parent . horizontalCenter
text: qsTr ( "Have you written down your password?" )
font.pixelSize: 22
font.bold: true
color: Theme . palette . directColor1
}
Column {
anchors.horizontalCenter: parent . horizontalCenter
spacing: Style . current . padding
StatusBaseText {
anchors.horizontalCenter: parent . horizontalCenter
text: qsTr ( "You will never be able to recover your password if you lose it." )
font.pixelSize: 12
color: Theme . palette . dangerColor1
}
StatusBaseText {
anchors.horizontalCenter: parent . horizontalCenter
text: qsTr ( "If you need to, write it using pen and paper and keep in a safe place." )
font.pixelSize: 12
color: Theme . palette . baseColor1
}
StatusBaseText {
anchors.horizontalCenter: parent . horizontalCenter
text: qsTr ( "If you lose your password you will lose access to your Status profile." )
font.pixelSize: 12
color: Theme . palette . baseColor1
}
}
// TODO replace with StatusInput as soon as it supports password
Input {
id: confPswInput
property bool showPassword: false
width: parent . width
enabled: ! submitBtn . loading
2022-03-07 22:59:38 +00:00
placeholderText: qsTr ( "Confirm you password (again)" )
2022-03-01 15:59:38 +00:00
textField.echoMode: showPassword ? TextInput.Normal : TextInput . Password
2022-03-22 09:29:59 +00:00
textField.validator: RegExpValidator { regExp: /^[!-~]{0,64}$/ } // That incudes NOT extended ASCII printable characters less space and a maximum of 64 characters allowed
2022-03-01 15:59:38 +00:00
keepHeight: true
textField.rightPadding: showHideCurrentIcon . width + showHideCurrentIcon . anchors . rightMargin + Style . current . padding / 2
StatusFlatRoundButton {
id: showHideCurrentIcon
visible: confPswInput . text !== ""
anchors.verticalCenter: parent . verticalCenter
anchors.right: parent . right
anchors.rightMargin: 16
width: 24
height: 24
icon.name: confPswInput . showPassword ? "hide" : "show"
icon.color: Theme . palette . baseColor1
onClicked: confPswInput . showPassword = ! confPswInput . showPassword
}
}
// Just a column filler to fit the design
Item {
height: Style . current . padding
width: parent . width
}
StatusButton {
id: submitBtn
anchors.horizontalCenter: parent . horizontalCenter
text: qsTr ( "Finalize Status Password Creation" )
2022-03-07 22:59:38 +00:00
enabled: ! submitBtn . loading && confPswInput . text === root . password
2022-03-01 15:59:38 +00:00
property Timer sim: Timer {
id: pause
interval: 20
onTriggered: {
2022-03-07 22:59:38 +00:00
// Create account operation blocks the UI so loading = true; will never have any affect until it is done.
// Getting around it with a small pause (timer) in order to get the desired behavior
OnboardingStore . finishCreatingAccount ( root . password )
2022-03-01 15:59:38 +00:00
}
}
onClicked: {
2022-03-07 22:59:38 +00:00
if ( OnboardingStore . accountCreated ) {
if ( root . password !== root . tmpPass ) {
OnboardingStore . changePassword ( root . tmpPass , root . password ) ;
root . tmpPass = root . password ;
} else {
submitBtn . loading = false
2022-03-15 22:27:36 +00:00
root . exit ( ) ;
2022-03-07 22:59:38 +00:00
}
} else {
root . tmpPass = root . password ;
submitBtn . loading = true
2022-03-15 22:27:36 +00:00
OnboardingStore . setCurrentAccountAndDisplayName ( root . displayName ) ;
2022-03-07 22:59:38 +00:00
pause . start ( ) ;
2022-03-23 19:51:39 +00:00
}
}
Connections {
target: onboardingModule
onAccountSetupError: {
if ( error === Constants . existingAccountError ) {
importLoginError . title = qsTr ( "Keys for this account already exist" )
importLoginError . text = qsTr ( "Keys for this account already exist and can't be added again. If you've lost your password, passcode or Keycard, uninstall the app, reinstall and access your keys by entering your seed phrase" )
} else {
//% "Login failed"
importLoginError . title = qsTrId ( "login-failed" )
//% "Login failed. Please re-enter your password and try again."
importLoginError . text = qsTrId ( "login-failed.-please-re-enter-your-password-and-try-again." )
}
importLoginError . open ( )
}
}
MessageDialog {
id: importLoginError
//% "Login failed"
title: qsTrId ( "login-failed" )
//% "Login failed. Please re-enter your password and try again."
text: qsTrId ( "login-failed.-please-re-enter-your-password-and-try-again." )
icon: StandardIcon . Critical
standardButtons: StandardButton . Ok
onVisibilityChanged: {
submitBtn . loading = false
2022-03-07 22:59:38 +00:00
}
2022-03-01 15:59:38 +00:00
}
}
}
// Back button:
StatusRoundButton {
enabled: ! submitBtn . loading
anchors.left: parent . left
anchors.leftMargin: Style . current . padding
anchors.bottom: parent . bottom
anchors.bottomMargin: Style . current . padding
icon.name: "arrow-left"
onClicked: { root . backClicked ( ) }
}
2022-03-07 22:59:38 +00:00
Connections {
target: startupModule
onAppStateChanged: {
if ( state === Constants . appState . main ) {
if ( ! ! OnboardingStore . profImgUrl ) {
2022-03-15 22:27:36 +00:00
OnboardingStore . saveImage ( ) ;
2022-03-07 22:59:38 +00:00
OnboardingStore . accountCreated = true ;
}
submitBtn . loading = false
2022-03-15 22:27:36 +00:00
root . exit ( )
2022-03-07 22:59:38 +00:00
}
}
}
Connections {
target: OnboardingStore . privacyModule
onPasswordChanged: {
if ( success ) {
submitBtn . loading = false
2022-03-15 22:27:36 +00:00
root . exit ( ) ;
2022-03-07 22:59:38 +00:00
}
}
}
2022-03-01 15:59:38 +00:00
}