~mhr3/unity8/fix-1297246

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
90
91
92
/*
 * Copyright (C) 2013 Canonical, Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * 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/>.
 *
 * Author: Michael Terry <michael.terry@canonical.com>
 */

#include "../Greeter.h"
#include "../GreeterPrivate.h"

namespace QLightDM
{

GreeterPrivate::GreeterPrivate(Greeter* parent)
  : authenticated(false),
    authenticationUser(),
    twoFactorDone(false),
    q_ptr(parent)
{
}

void GreeterPrivate::handleAuthenticate()
{
    Q_Q(Greeter);

    // Send out any messages we need to
    if (authenticationUser == "info-prompt")
        Q_EMIT q->showMessage("Welcome to Unity Greeter", Greeter::MessageTypeInfo);
    else if (authenticationUser == "wide-info-prompt")
        Q_EMIT q->showMessage("Welcome to Unity Greeter, the greeteriest greeter that ever did appear in these fine lands", Greeter::MessageTypeInfo);
    else if (authenticationUser == "html-info-prompt")
        Q_EMIT q->showMessage("<b>&</b>", Greeter::MessageTypeInfo);
    else if (authenticationUser == "long-info-prompt")
        Q_EMIT q->showMessage("Welcome to Unity Greeter\n\nWe like to annoy you with super ridiculously long messages.\nLike this one\n\nThis is the last line of a multiple line message.", Greeter::MessageTypeInfo);
    else if (authenticationUser == "multi-info-prompt") {
        Q_EMIT q->showMessage("Welcome to Unity Greeter", Greeter::MessageTypeInfo);
        Q_EMIT q->showMessage("This is an error", Greeter::MessageTypeError);
        Q_EMIT q->showMessage("You should have seen three messages", Greeter::MessageTypeInfo);
    }

    // OK, now actually do the prompt
    if (authenticationUser == "no-password") {
        authenticated = true;
        Q_EMIT q->authenticationComplete();
    } else if (authenticationUser == "auth-error") {
        authenticated = false;
        Q_EMIT q->authenticationComplete();
    } else if (authenticationUser == "different-prompt") {
        Q_EMIT q->showPrompt("Secret word: ", Greeter::PromptTypeSecret);
    } else {
        Q_EMIT q->showPrompt("Password: ", Greeter::PromptTypeSecret);
    }
}

void GreeterPrivate::handleRespond(const QString &response)
{
    Q_Q(Greeter);

    if (authenticationUser == "no-response")
        return;
    else if (authenticationUser == "two-factor") {
        if (!twoFactorDone) {
            if (response == "password") {
                twoFactorDone = true;
                Q_EMIT q->showPrompt("otp", Greeter::PromptTypeQuestion);
            } else {
                authenticated = false;
                Q_EMIT q->authenticationComplete();
            }
        } else {
            authenticated = (response == "otp");
            Q_EMIT q->authenticationComplete();
        }
        return;
    }

    authenticated = (response == "password");
    Q_EMIT q->authenticationComplete();
}

}