Debian Codegraph @

src/app/qml/authentication/AuthenticationHandler.qml

raw
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 import Lomiri.Components.Extras.PamAuthentication 0.1
22 //import Biometryd 0.0
23
24 Item {
25 id: handler
26
27 property string serviceName
28
29 // TODO: We keep fingerprint authentication disabled for now
30 readonly property bool isFingerprintAvailable: false //Biometryd.available
31
32 readonly property bool isAlphanumeric: true // TODO: Implement
33
34 property bool requireAuthentication: true
35
36 function authenticate() {
37 if (handler.isFingerprintAvailable) {
38 var popup = PopupUtils.open(Qt.resolvedUrl("FingerprintDialog.qml"))
39
40 popup.succeeded.connect(function() {
41 handler.authenticationSucceeded()
42 })
43
44 popup.aborted.connect(function() {
45 handler.authenticationAborted()
46 })
47
48 popup.failed.connect(function(reason) {
49 handler.authenticationFailed("fingerprint", reason)
50 })
51
52 popup.usePasswordRequested.connect(function() {
53 var passwordPopup = PopupUtils.open(Qt.resolvedUrl("PasswordDialog.qml"), QuickUtils.rootItem(handler), { isAlphanumeric: handler.isAlphanumeric, pamAuthentication: __pam })
54
55 passwordPopup.succeeded.connect(function() {
56 handler.authenticationSucceeded()
57 })
58
59 passwordPopup.aborted.connect(function() {
60 handler.authenticationAborted()
61 })
62
63 passwordPopup.failed.connect(function(reason) {
64 handler.authenticationFailed("password", reason)
65 })
66 })
67 } else {
68 var passwordPopup = PopupUtils.open(Qt.resolvedUrl("PasswordDialog.qml"), QuickUtils.rootItem(handler), { isAlphanumeric: handler.isAlphanumeric, pamAuthentication: __pam })
69
70 passwordPopup.succeeded.connect(function() {
71 handler.authenticationSucceeded()
72 })
73
74 passwordPopup.aborted.connect(function() {
75 handler.authenticationAborted()
76 })
77
78 passwordPopup.failed.connect(function(reason) {
79 handler.authenticationFailed("password", reason)
80 })
81 }
82 }
83
84 signal authenticationSucceeded()
85 signal authenticationFailed(var type, var reason)
86 signal authenticationAborted()
87
88 Component.onCompleted: {
89 handler.requireAuthentication = __pam.requireAuthentication()
90 }
91
92 PamAuthentication {
93 id: __pam
94 serviceName: handler.serviceName
95 }
96 }