This repository was archived by the owner on Dec 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPasswordDialog.qml
89 lines (74 loc) · 2.8 KB
/
PasswordDialog.qml
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
/*
* Copyright (C) 2017 Stefano Verzegnassi
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License 3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
import QtQuick 2.4
import Ubuntu.Components 1.3
import Ubuntu.Components.Popups 1.3
Dialog {
id: authenticationDialog
property bool isAlphanumeric: true
property var pamAuthentication
property string message: authenticationDialog.isAlphanumeric
? i18n.tr("Your passphrase is required to access restricted content")
: i18n.tr("Your passcode is required to access restricted content")
function authenticate() {
if (pamAuthentication.validatePasswordToken(passwordField.text)) {
authenticationDialog.succeeded()
PopupUtils.close(authenticationDialog)
} else {
errorHint.visible = true
passwordField.text = ""
authenticationDialog.failed(i18n.tr("Authentication failed"))
}
}
signal succeeded()
signal failed(var reason)
signal aborted()
title: authenticationDialog.isAlphanumeric ? i18n.tr("Passphrase required") : i18n.tr("Passcode required")
text: authenticationDialog.message
Component.onCompleted: {
if (!authenticationDialog.isAlphanumeric)
passwordField.inputMethodHints |= Qt.ImhDigitsOnly
passwordField.forceActiveFocus()
}
TextField {
id: passwordField
placeholderText: authenticationDialog.isAlphanumeric ? i18n.tr("passphrase") : i18n.tr("passcode")
echoMode: TextInput.Password
inputMethodHints: Qt.ImhHiddenText | Qt.ImhSensitiveData |
Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
onAccepted: authenticationDialog.authenticate()
}
Label {
id: errorHint
color: UbuntuColors.red
text: i18n.tr("Authentication failed. Please retry")
visible: false
}
Button {
text: i18n.tr("Authenticate")
color: UbuntuColors.green
onClicked: authenticationDialog.authenticate()
}
Button {
text: i18n.tr("Cancel")
color: UbuntuColors.graphite
onClicked: {
authenticationDialog.aborted()
PopupUtils.close(authenticationDialog)
}
}
}