~verzegnassi-stefano/+junk/ubuntu-terminal-app-uitk13

« back to all changes in this revision

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

  • Committer: Filippo Scognamiglio
  • Date: 2014-10-25 04:42:31 UTC
  • Revision ID: flscogna@gmail.com-20141025044231-javjhusbqa171127
Initial reboot commit.

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.3
 
17
import Ubuntu.Components 1.1
 
18
import Ubuntu.Components.Popups 0.1
 
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
    signal granted()
 
30
    signal denied()
 
31
 
 
32
    Component.onCompleted: {
 
33
        if ( systemAuthentication.requireAuthentication() && !noAuthentication) {
 
34
            displayLoginDialog();
 
35
        }
 
36
    }
 
37
 
 
38
    /**
 
39
     Displays the login dialog
 
40
     and fires success or failure depending
 
41
     on user input.
 
42
     */
 
43
    function displayLoginDialog() {
 
44
        var authentication_dialog =
 
45
            PopupUtils.open( Qt.resolvedUrl( "AuthenticationDialog.qml" ),
 
46
                             authenticationService );
 
47
 
 
48
        var verify_password = function( password ) {
 
49
            if ( systemAuthentication.validatePasswordToken( password ) ) {
 
50
                granted();
 
51
                PopupUtils.close( authentication_dialog );
 
52
            }
 
53
            else {
 
54
                var dialog_options = {
 
55
                    title : i18n.tr( "Authentication failed" )
 
56
                };
 
57
 
 
58
                PopupUtils.open( Qt.resolvedUrl( "NotifyDialog.qml" ),
 
59
                                 authenticationService,
 
60
                                 dialog_options );
 
61
            }
 
62
        };
 
63
 
 
64
        authentication_dialog.passwordEntered.connect( verify_password );
 
65
        authentication_dialog.dialogCanceled.connect( denied );
 
66
    }
 
67
 
 
68
    PamAuthentication {
 
69
        id: systemAuthentication
 
70
        serviceName: "terminal"
 
71
    }
 
72
}