-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathLoginKeycardBox.qml
More file actions
261 lines (242 loc) · 8.27 KB
/
LoginKeycardBox.qml
File metadata and controls
261 lines (242 loc) · 8.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import StatusQ.Core
import StatusQ.Controls
import StatusQ.Controls.Validators
import StatusQ.Core.Theme
import AppLayouts.Onboarding.enums
import AppLayouts.Onboarding.controls
Control {
id: root
required property int keycardState
required property bool isWrongKeycard
required property int keycardRemainingPinAttempts
required property int keycardRemainingPukAttempts
property string loginError
required property bool isBiometricsLogin
required property bool biometricsSuccessful
required property bool biometricsFailed
signal biometricsRequested()
signal pinEditedManually()
signal detailedErrorPopupRequested()
signal unblockWithSeedphraseRequested()
signal unblockWithPukRequested()
signal loginRequested(string pin)
function clear() {
d.wrongPin = false
pinInputField.statesInitialization()
pinInputField.forceFocus()
}
function markAsWrongPin() {
d.wrongPin = true
pinInputField.statesInitialization()
pinInputField.forceFocus()
}
function setPin(pin: string) {
pinInputField.setPin(pin)
}
horizontalPadding: Theme.padding
verticalPadding: 20
QtObject {
id: d
property bool wrongPin
}
background: Rectangle {
color: "transparent"
border.width: 1
border.color: Theme.palette.baseColor2
radius: Theme.radius
}
contentItem: ColumnLayout {
spacing: 12
LoginTouchIdIndicator {
Layout.alignment: Qt.AlignHCenter
Layout.topMargin: Theme.halfPadding
id: touchIdIcon
visible: false
success: root.biometricsSuccessful
error: root.biometricsFailed
onClicked: root.biometricsRequested()
}
StatusBaseText {
Layout.fillWidth: true
id: infoText
horizontalAlignment: Qt.AlignHCenter
elide: Text.ElideRight
color: Theme.palette.baseColor1
linkColor: hoveredLink ? Theme.palette.hoverColor(color) : color
HoverHandler {
cursorShape: !!parent.hoveredLink ? Qt.PointingHandCursor : undefined
}
onLinkActivated: root.detailedErrorPopupRequested()
}
Column {
id: lockedButtons
Layout.fillWidth: true
spacing: 12
visible: false
MaybeOutlineButton {
objectName: "btnUnblockWithPUK"
width: parent.width
visible: root.keycardState === Onboarding.KeycardState.BlockedPIN && root.keycardRemainingPukAttempts > 0
text: qsTr("Unblock with PUK")
onClicked: root.unblockWithPukRequested()
}
MaybeOutlineButton {
objectName: "btnUnblockWithSeedphrase"
width: parent.width
visible: root.keycardState === Onboarding.KeycardState.BlockedPIN || root.keycardState === Onboarding.KeycardState.BlockedPUK
text: qsTr("Unblock with recovery phrase")
onClicked: root.unblockWithSeedphraseRequested()
}
}
StatusPinInput {
Layout.alignment: Qt.AlignHCenter
id: pinInputField
objectName: "pinInput"
validator: StatusIntValidator { bottom: 0; top: 999999 }
visible: false
inputMethodHints: Qt.ImhDigitsOnly
onPinInputChanged: {
if (pinInput.length === 6) {
root.loginRequested(pinInput)
}
}
onPinEditedManually: {
d.wrongPin = false
root.pinEditedManually()
}
}
}
states: [
// normal/intro states
State {
name: "plugin"
when: root.keycardState === Onboarding.KeycardState.PluginReader
PropertyChanges {
target: infoText
text: qsTr("Plug in Keycard reader...")
}
},
State {
name: "insert"
when: root.keycardState === Onboarding.KeycardState.InsertKeycard
PropertyChanges {
target: infoText
text: qsTr("Insert your Keycard...")
}
},
State {
name: "reading"
when: root.keycardState === Onboarding.KeycardState.ReadingKeycard
PropertyChanges {
target: infoText
text: qsTr("Reading Keycard...")
}
},
// error states
State {
name: "notKeycard"
when: root.keycardState === Onboarding.KeycardState.NotKeycard
PropertyChanges {
target: infoText
color: Theme.palette.dangerColor1
text: qsTr("Oops this isn't a Keycard.<br>Remove card and insert a Keycard.")
}
},
State {
name: "wrongKeycard"
when: root.isWrongKeycard
PropertyChanges {
target: infoText
color: Theme.palette.dangerColor1
text: qsTr("Wrong Keycard for this profile inserted")
}
},
State {
name: "genericError"
when: root.keycardState === -1 ||
root.keycardState === Onboarding.KeycardState.NoPCSCService ||
root.keycardState === Onboarding.KeycardState.MaxPairingSlotsReached // TODO add a generic/fallback keycard error here too
PropertyChanges {
target: infoText
color: Theme.palette.dangerColor1
text: qsTr("Issue detecting Keycard.<br>Remove and re-insert reader and Keycard.")
}
},
State {
name: "blocked"
when: root.keycardState === Onboarding.KeycardState.BlockedPIN ||
root.keycardState === Onboarding.KeycardState.BlockedPUK
PropertyChanges {
target: infoText
color: Theme.palette.dangerColor1
text: qsTr("Keycard blocked")
}
PropertyChanges {
target: lockedButtons
visible: true
}
},
State {
name: "empty"
when: root.keycardState === Onboarding.KeycardState.Empty
PropertyChanges {
target: infoText
color: Theme.palette.dangerColor1
text: qsTr("The inserted Keycard is empty.<br>Insert the correct Keycard for this profile.")
}
},
State {
name: "wrongPin"
extend: "notEmpty"
when: root.keycardState === Onboarding.KeycardState.NotEmpty && d.wrongPin
PropertyChanges {
target: infoText
color: Theme.palette.dangerColor1
text: qsTr("PIN incorrect. %n attempt(s) remaining.", "", root.keycardRemainingPinAttempts)
}
},
State {
name: "errorDuringLogin"
when: !!root.loginError
PropertyChanges {
target: infoText
color: Theme.palette.dangerColor1
text: qsTr("Login failed. %1").arg("<a href='#details'>" + qsTr("Show details.") + "</a>")
}
},
// exit states
State {
name: "notEmpty"
when: root.keycardState === Onboarding.KeycardState.NotEmpty && !d.wrongPin
PropertyChanges {
target: infoText
text: qsTr("Enter Keycard PIN")
}
PropertyChanges {
target: pinInputField
visible: true
focus: true
}
PropertyChanges {
target: background
border.color: Theme.palette.primaryColor1
}
StateChangeScript {
script: {
pinInputField.forceFocus()
}
}
PropertyChanges {
target: touchIdIcon
visible: root.isBiometricsLogin
}
}
]
TapHandler {
enabled: pinInputField.visible
onTapped: pinInputField.forceFocus()
}
}