| 1 |
/* |
| 2 |
* Copyright (C) 2017 Stefano Verzegnassi |
| 3 |
* |
| 4 |
* This program is free software: you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License 3 as published by |
| 6 |
* the Free Software Foundation, either version 3 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program. If not, see http://www.gnu.org/licenses/. |
| 16 |
*/ |
| 17 |
|
| 18 |
import QtQuick 2.4 |
| 19 |
import Lomiri.Components 1.3 |
| 20 |
import Lomiri.Components.Popups 1.3 |
| 21 |
|
| 22 |
Dialog { |
| 23 |
id: authenticationDialog |
| 24 |
|
| 25 |
property bool isAlphanumeric: true |
| 26 |
property var pamAuthentication |
| 27 |
|
| 28 |
function authenticate() { |
| 29 |
if (pamAuthentication.validatePasswordToken(passwordField.text)) { |
| 30 |
authenticationDialog.succeeded() |
| 31 |
PopupUtils.close(authenticationDialog) |
| 32 |
} else { |
| 33 |
errorHint.visible = true |
| 34 |
passwordField.text = "" |
| 35 |
authenticationDialog.failed(i18n.tr("Authentication failed")) |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
signal succeeded() |
| 40 |
signal failed(var reason) |
| 41 |
signal aborted() |
| 42 |
|
| 43 |
title: i18n.tr("Authentication required") |
| 44 |
text: authenticationDialog.isAlphanumeric |
| 45 |
? i18n.tr("Your passphrase is required to access restricted content") |
| 46 |
: i18n.tr("Your passcode is required to access restricted content") |
| 47 |
|
| 48 |
Component.onCompleted: { |
| 49 |
if (!authenticationDialog.isAlphanumeric) |
| 50 |
passwordField.inputMethodHints |= Qt.ImhDigitsOnly |
| 51 |
|
| 52 |
passwordField.forceActiveFocus() |
| 53 |
} |
| 54 |
|
| 55 |
TextField { |
| 56 |
id: passwordField |
| 57 |
placeholderText: handler.isPassphrase ? i18n.tr("passphrase (default is 0000 if unset)") : i18n.tr("passcode (default is 0000 if unset)") |
| 58 |
echoMode: TextInput.Password |
| 59 |
|
| 60 |
inputMethodHints: Qt.ImhHiddenText | Qt.ImhSensitiveData | |
| 61 |
Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText |
| 62 |
|
| 63 |
onAccepted: authenticationDialog.authenticate() |
| 64 |
} |
| 65 |
|
| 66 |
Label { |
| 67 |
id: errorHint |
| 68 |
color: theme.palette.normal.negative |
| 69 |
text: i18n.tr("Authentication failed. Please retry") |
| 70 |
visible: false |
| 71 |
} |
| 72 |
|
| 73 |
Button { |
| 74 |
text: i18n.tr("Authenticate") |
| 75 |
color: theme.palette.normal.positive |
| 76 |
onClicked: authenticationDialog.authenticate() |
| 77 |
} |
| 78 |
|
| 79 |
Button { |
| 80 |
text: i18n.tr("Cancel") |
| 81 |
onClicked: { |
| 82 |
authenticationDialog.aborted() |
| 83 |
PopupUtils.close(authenticationDialog) |
| 84 |
} |
| 85 |
} |
| 86 |
} |