on 551c708 help sign in
unity8/tests/mocks/LightDM/full/GreeterPrivate.cpp
98 lines 3.6 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 == "has-pin"){
57 Q_EMIT q->showPrompt("PIN", Greeter::PromptTypeSecret);
58 } else if (authenticationUser == "auth-error") {
59 authenticated = false;
60 Q_EMIT q->authenticationComplete();
61 } else if (authenticationUser == "different-prompt") {
62 Q_EMIT q->showPrompt("Secret word: ", Greeter::PromptTypeSecret);
63 } else {
64 Q_EMIT q->showPrompt("Password: ", Greeter::PromptTypeSecret);
65 }
68void GreeterPrivate::handleRespond(const QString &response)
70 Q_Q(Greeter);
72 if (authenticationUser == "no-response")
73 return;
74 else if (authenticationUser == "two-factor") {
75 if (!twoFactorDone) {
76 if (response == "password") {
77 twoFactorDone = true;
78 Q_EMIT q->showPrompt("otp", Greeter::PromptTypeQuestion);
79 } else {
80 authenticated = false;
81 Q_EMIT q->authenticationComplete();
82 }
83 } else {
84 authenticated = (response == "otp");
85 Q_EMIT q->authenticationComplete();
86 }
87 return;
88 }
90 if (authenticationUser == "has-pin") {
91 authenticated = (response == "1234");
92 } else {
93 authenticated = (response == "password");
94 }
95 Q_EMIT q->authenticationComplete();