~larryprice/acolyterm/release-0.1

« back to all changes in this revision

Viewing changes to src/app/qml/AuthenticationService.qml

  • Committer: Tarmac
  • Author(s): Larry Price
  • Date: 2016-06-22 16:14:21 UTC
  • mfrom: (210.1.5 acolyterm)
  • Revision ID: tarmac-20160622161421-cnyw0bjrpdig3238
Use pkexec to run default terminal and remove dependency on pam. Fixes: https://bugs.launchpad.net/bugs/1593399.

Approved by Libertine CI Bot, Larry Price.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2014 Canonical Ltd
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 version 3 as
6
 
 * published by the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License
14
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 */
16
 
import QtQuick 2.4
17
 
import Ubuntu.Components 1.3
18
 
import Ubuntu.Components.Popups 1.3
19
 
import com.ubuntu.PamAuthentication 0.1
20
 
 
21
 
/**
22
 
 A simple service for authentication.
23
 
 Displays login dialog and fires signals
24
 
 on access approval or denial.
25
 
 */
26
 
Item {
27
 
    id: authenticationService
28
 
 
29
 
    property var __authDialog
30
 
    readonly property bool isDialogVisible: __authDialog != null
31
 
 
32
 
    signal granted()
33
 
    signal denied()
34
 
 
35
 
    Component.onCompleted: {
36
 
        if ( systemAuthentication.requireAuthentication() && !noAuthentication) {
37
 
            displayLoginDialog();
38
 
        }
39
 
    }
40
 
 
41
 
    /**
42
 
     Displays the login dialog
43
 
     and fires success or failure depending
44
 
     on user input.
45
 
     */
46
 
    function displayLoginDialog() {
47
 
        var authentication_dialog =
48
 
            PopupUtils.open( Qt.resolvedUrl( "AuthenticationDialog.qml" ),
49
 
                             authenticationService );
50
 
 
51
 
        var verify_password = function( password ) {
52
 
            if ( systemAuthentication.validatePasswordToken( password ) ) {
53
 
                granted();
54
 
                PopupUtils.close( authentication_dialog );
55
 
            }
56
 
            else {
57
 
                var dialog_options = {
58
 
                    title : i18n.tr( "Authentication failed" )
59
 
                };
60
 
 
61
 
                PopupUtils.open( Qt.resolvedUrl( "NotifyDialog.qml" ),
62
 
                                 authenticationService,
63
 
                                 dialog_options );
64
 
            }
65
 
        };
66
 
 
67
 
        authentication_dialog.passwordEntered.connect( verify_password );
68
 
        authentication_dialog.dialogCanceled.connect( denied );
69
 
 
70
 
        __authDialog = authentication_dialog
71
 
    }
72
 
 
73
 
    PamAuthentication {
74
 
        id: systemAuthentication
75
 
        serviceName: "terminal"
76
 
    }
77
 
}