on a4713ff help sign in
unity8/tests/mocks/LightDM/full/GreeterPrivate.cpp
92 lines 3.3 kB history raw
1/*
2 * Copyright (C) 2013 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 as published by
6 * the Free Software Foundation; version 3.
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 * Author: Michael Terry <michael.terry@canonical.com>
17 */
19#include "../Greeter.h"
20#include "../GreeterPrivate.h"
22namespace QLightDM
25GreeterPrivate::GreeterPrivate(Greeter* parent)
26 : authenticated(false),
27 authenticationUser(),
28 twoFactorDone(false),
29 q_ptr(parent)
33void GreeterPrivate::handleAuthenticate()
35 Q_Q(Greeter);
37 // Send out any messages we need to
38 if (authenticationUser == "info-prompt")
39 Q_EMIT q->showMessage("Welcome to Unity Greeter", Greeter::MessageTypeInfo);
40 else if (authenticationUser == "wide-info-prompt")
41 Q_EMIT q->showMessage("Welcome to Unity Greeter, the greeteriest greeter that ever did appear in these fine lands", Greeter::MessageTypeInfo);
42 else if (authenticationUser == "html-info-prompt")
43 Q_EMIT q->showMessage("<b>&</b>", Greeter::MessageTypeInfo);
44 else if (authenticationUser == "long-info-prompt")
45 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);
46 else if (authenticationUser == "multi-info-prompt") {
47 Q_EMIT q->showMessage("Welcome to Unity Greeter", Greeter::MessageTypeInfo);
48 Q_EMIT q->showMessage("This is an error", Greeter::MessageTypeError);
49 Q_EMIT q->showMessage("You should have seen three messages", Greeter::MessageTypeInfo);
50 }
52 // OK, now actually do the prompt
53 if (authenticationUser == "no-password") {
54 authenticated = true;
55 Q_EMIT q->authenticationComplete();
56 } else if (authenticationUser == "auth-error") {
57 authenticated = false;
58 Q_EMIT q->authenticationComplete();
59 } else if (authenticationUser == "different-prompt") {
60 Q_EMIT q->showPrompt("Secret word: ", Greeter::PromptTypeSecret);
61 } else {
62 Q_EMIT q->showPrompt("Password: ", Greeter::PromptTypeSecret);
63 }
66void GreeterPrivate::handleRespond(const QString &response)
68 Q_Q(Greeter);
70 if (authenticationUser == "no-response")
71 return;
72 else if (authenticationUser == "two-factor") {
73 if (!twoFactorDone) {
74 if (response == "password") {
75 twoFactorDone = true;
76 Q_EMIT q->showPrompt("otp", Greeter::PromptTypeQuestion);
77 } else {
78 authenticated = false;
79 Q_EMIT q->authenticationComplete();
80 }
81 } else {
82 authenticated = (response == "otp");
83 Q_EMIT q->authenticationComplete();
84 }
85 return;
86 }
88 authenticated = (response == "password");
89 Q_EMIT q->authenticationComplete();