2 * Copyright (C) 2014-2016 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/>.
17#include "MockController.h"
18#include "MockGreeter.h"
19#include <QDBusInterface>
20#include <QDBusPendingCall>
29 bool authenticated = false;
30 QString authenticationUser;
31 bool twoFactorDone = false;
34Greeter::Greeter(QObject *parent)
36 , d_ptr(new GreeterPrivate)
45QString Greeter::authenticationUser() const
49 return d->authenticationUser;
52bool Greeter::hasGuestAccountHint() const
57QString Greeter::getHint(const QString &name) const
63QString Greeter::defaultSessionHint() const
65 return QStringLiteral("ubuntu");
68bool Greeter::hideUsersHint() const
73bool Greeter::showManualLoginHint() const
78bool Greeter::showRemoteLoginHint() const
83QString Greeter::selectUserHint() const
85 return MockController::instance()->selectUserHint();
88bool Greeter::selectGuestHint() const
93QString Greeter::autologinUserHint() const
98bool Greeter::autologinGuestHint() const
103int Greeter::autologinTimeoutHint() const
108bool Greeter::inAuthentication() const
113QString Greeter::hostname() const
118bool Greeter::isAuthenticated() const
122 return d->authenticated;
125bool Greeter::connectSync()
130void Greeter::authenticate(const QString &username)
134 d->authenticated = false;
135 d->authenticationUser = username;
136 d->twoFactorDone = false;
137 QTimer::singleShot(0, this, &Greeter::handleAuthenticate);
140void Greeter::handleAuthenticate()
144 // Send out any messages we need to
145 if (d->authenticationUser == "info-prompt")
146 Q_EMIT showMessage("Welcome to Unity Greeter", Greeter::MessageTypeInfo);
147 else if (d->authenticationUser == "wide-info-prompt")
148 Q_EMIT showMessage("Welcome to Unity Greeter, the greeteriest greeter that ever did appear in these fine lands", Greeter::MessageTypeInfo);
149 else if (d->authenticationUser == "html-info-prompt")
150 Q_EMIT showMessage("<b>&</b>", Greeter::MessageTypeInfo);
151 else if (d->authenticationUser == "long-info-prompt")
152 Q_EMIT 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);
153 else if (d->authenticationUser == "multi-info-prompt") {
154 Q_EMIT showMessage("Welcome to Unity Greeter", Greeter::MessageTypeInfo);
155 Q_EMIT showMessage("This is an error", Greeter::MessageTypeError);
156 Q_EMIT showMessage("You should have seen three messages", Greeter::MessageTypeInfo);
159 // OK, now actually do the prompt
160 if (d->authenticationUser == "no-password") {
161 d->authenticated = true;
162 Q_EMIT authenticationComplete();
163 } else if (d->authenticationUser == "has-pin"){
164 Q_EMIT showPrompt("Password: ", Greeter::PromptTypeSecret);
165 } else if (d->authenticationUser == "auth-error") {
166 d->authenticated = false;
167 Q_EMIT authenticationComplete();
168 } else if (d->authenticationUser == "different-prompt") {
169 Q_EMIT showPrompt("Secret word: ", Greeter::PromptTypeSecret);
171 Q_EMIT showPrompt("Password: ", Greeter::PromptTypeSecret);
175void Greeter::authenticateAsGuest()
178void Greeter::authenticateAutologin()
181void Greeter::authenticateRemote(const QString &session, const QString &username)
187void Greeter::cancelAuthentication()
190void Greeter::setLanguage (const QString &language)
195bool Greeter::startSessionSync(const QString &session)
199 // Send a request to hide the greeter. This is normally done by logind,
200 // but when testing, we don't want the bother of mocking that out. Instead,
201 // just send the request directly ourselves.
202 QDBusInterface iface("com.canonical.UnityGreeter",
204 "com.canonical.UnityGreeter",
205 QDBusConnection::sessionBus());
206 iface.asyncCall("HideGreeter");
211void Greeter::respond(const QString &response)
215 if (d->authenticationUser == "no-response")
217 else if (d->authenticationUser == "two-factor") {
218 if (!d->twoFactorDone) {
219 if (response == "password") {
220 d->twoFactorDone = true;
221 Q_EMIT showPrompt("otp", Greeter::PromptTypeQuestion);
223 d->authenticated = false;
224 sendAuthenticationComplete();
227 d->authenticated = (response == "otp");
228 sendAuthenticationComplete();
233 if (d->authenticationUser == "has-pin") {
234 d->authenticated = (response == "1234");
236 d->authenticated = (response == "password");
238 sendAuthenticationComplete();
241void Greeter::sendAuthenticationComplete()
243 if (qgetenv("UNITY_TESTING").isEmpty()) {
244 // simulate PAM's delay
245 QTimer::singleShot(1000, this, &Greeter::authenticationComplete);
247 Q_EMIT authenticationComplete();
251QObject *Greeter::mock()
253 return MockController::instance();
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list