2
* Copyright (C) 2014 Canonical, Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; version 3.
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.
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/>.
18
#include "GreeterPrivate.h"
23
GreeterPrivate::GreeterPrivate(Greeter* parent)
24
: authenticated(false),
30
char *envMockMode = getenv("LIBLIGHTDM_MOCK_MODE");
32
mockMode = envMockMode;
36
void GreeterPrivate::handleAuthenticate()
40
if (mockMode == "single") {
42
Q_EMIT q->authenticationComplete();
43
} else if (mockMode == "single-passphrase" || mockMode == "single-pin") {
44
Q_EMIT q->showPrompt("Password: ", Greeter::PromptTypeSecret);
45
} else if (mockMode == "full") {
46
handleAuthenticate_full();
50
void GreeterPrivate::handleAuthenticate_full()
54
// Send out any messages we need to
55
if (authenticationUser == "info-prompt")
56
Q_EMIT q->showMessage("Welcome to Unity Greeter", Greeter::MessageTypeInfo);
57
else if (authenticationUser == "wide-info-prompt")
58
Q_EMIT q->showMessage("Welcome to Unity Greeter, the greeteriest greeter that ever did appear in these fine lands", Greeter::MessageTypeInfo);
59
else if (authenticationUser == "html-info-prompt")
60
Q_EMIT q->showMessage("<b>&</b>", Greeter::MessageTypeInfo);
61
else if (authenticationUser == "long-info-prompt")
62
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);
63
else if (authenticationUser == "multi-info-prompt") {
64
Q_EMIT q->showMessage("Welcome to Unity Greeter", Greeter::MessageTypeInfo);
65
Q_EMIT q->showMessage("This is an error", Greeter::MessageTypeError);
66
Q_EMIT q->showMessage("You should have seen three messages", Greeter::MessageTypeInfo);
69
// OK, now actually do the prompt
70
if (authenticationUser == "no-password") {
72
Q_EMIT q->authenticationComplete();
73
} else if (authenticationUser == "has-pin"){
74
Q_EMIT q->showPrompt("Password: ", Greeter::PromptTypeSecret);
75
} else if (authenticationUser == "auth-error") {
76
authenticated = false;
77
Q_EMIT q->authenticationComplete();
78
} else if (authenticationUser == "different-prompt") {
79
Q_EMIT q->showPrompt("Secret word: ", Greeter::PromptTypeSecret);
81
Q_EMIT q->showPrompt("Password: ", Greeter::PromptTypeSecret);
85
void GreeterPrivate::handleRespond(QString const &response)
89
if (mockMode == "single") {
91
} else if (mockMode == "single-passphrase") {
92
authenticated = (response == "password");
93
q->sendAuthenticationComplete();
94
} else if (mockMode == "single-pin") {
95
authenticated = (response == "1234");
96
q->sendAuthenticationComplete();
97
} else if (mockMode == "full") {
98
handleRespond_full(response);
102
void GreeterPrivate::handleRespond_full(const QString &response)
106
if (authenticationUser == "no-response")
108
else if (authenticationUser == "two-factor") {
109
if (!twoFactorDone) {
110
if (response == "password") {
111
twoFactorDone = true;
112
Q_EMIT q->showPrompt("otp", Greeter::PromptTypeQuestion);
114
authenticated = false;
115
q->sendAuthenticationComplete();
118
authenticated = (response == "otp");
119
q->sendAuthenticationComplete();
124
if (authenticationUser == "has-pin") {
125
authenticated = (response == "1234");
127
authenticated = (response == "password");
129
q->sendAuthenticationComplete();