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
54 return MockController::instance()->hasGuestAccountHint();
57QString Greeter::getHint(const QString &name) const
63QString Greeter::defaultSessionHint() const
65 return QStringLiteral("ubuntu");
68bool Greeter::hideUsersHint() const
70 return MockController::instance()->hideUsersHint();
73bool Greeter::showManualLoginHint() const
75 return MockController::instance()->showManualLoginHint();
78bool Greeter::showRemoteLoginHint() const
83QString Greeter::selectUserHint() const
85 return MockController::instance()->selectUserHint();
88bool Greeter::selectGuestHint() const
90 return MockController::instance()->selectGuestHint();
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 if (d->authenticationUser.isEmpty()) {
145 Q_EMIT showPrompt("Username: ", Greeter::PromptTypeQuestion);
149 // Send out any messages we need to
150 if (d->authenticationUser == "info-prompt")
151 Q_EMIT showMessage("Welcome to Unity Greeter", Greeter::MessageTypeInfo);
152 else if (d->authenticationUser == "wide-info-prompt")
153 Q_EMIT showMessage("Welcome to Unity Greeter, the greeteriest greeter that ever did appear in these fine lands", Greeter::MessageTypeInfo);
154 else if (d->authenticationUser == "html-info-prompt")
155 Q_EMIT showMessage("<b>&</b>", Greeter::MessageTypeInfo);
156 else if (d->authenticationUser == "long-info-prompt")
157 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);
158 else if (d->authenticationUser == "multi-info-prompt") {
159 Q_EMIT showMessage("Welcome to Unity Greeter", Greeter::MessageTypeInfo);
160 Q_EMIT showMessage("This is an error", Greeter::MessageTypeError);
161 Q_EMIT showMessage("You should have seen three messages", Greeter::MessageTypeInfo);
164 // OK, now actually do the prompt
165 if (d->authenticationUser == "no-password") {
166 d->authenticated = true;
167 Q_EMIT authenticationComplete();
168 } else if (d->authenticationUser == "has-pin"){
169 Q_EMIT showPrompt("Password: ", Greeter::PromptTypeSecret);
170 } else if (d->authenticationUser == "auth-error") {
171 d->authenticated = false;
172 Q_EMIT authenticationComplete();
173 } else if (d->authenticationUser == "different-prompt") {
174 Q_EMIT showPrompt("Secret word: ", Greeter::PromptTypeSecret);
176 Q_EMIT showPrompt("Password: ", Greeter::PromptTypeSecret);
180void Greeter::authenticateAsGuest()
184 d->authenticated = true;
185 d->authenticationUser = QString(); // this is what the real liblightdm does
186 d->twoFactorDone = false;
187 QTimer::singleShot(0, this, &Greeter::authenticationComplete);
190void Greeter::authenticateAutologin()
193void Greeter::authenticateRemote(const QString &session, const QString &username)
199void Greeter::cancelAuthentication()
202void Greeter::setLanguage (const QString &language)
207bool Greeter::startSessionSync(const QString &session)
211 // Send a request to hide the greeter. This is normally done by logind,
212 // but when testing, we don't want the bother of mocking that out. Instead,
213 // just send the request directly ourselves.
214 QDBusInterface iface("com.canonical.UnityGreeter",
216 "com.canonical.UnityGreeter",
217 QDBusConnection::sessionBus());
218 iface.asyncCall("HideGreeter");
223void Greeter::respond(const QString &response)
227 if (d->authenticationUser.isEmpty()) {
228 // A manual login, our first question was which username
229 d->authenticationUser = response;
230 handleAuthenticate();
234 if (d->authenticationUser == "no-response")
236 else if (d->authenticationUser == "two-factor") {
237 if (!d->twoFactorDone) {
238 if (response == "password") {
239 d->twoFactorDone = true;
240 Q_EMIT showPrompt("otp", Greeter::PromptTypeQuestion);
242 d->authenticated = false;
243 sendAuthenticationComplete();
246 d->authenticated = (response == "otp");
247 sendAuthenticationComplete();
252 if (d->authenticationUser == "has-pin") {
253 d->authenticated = (response == "1234");
255 d->authenticated = (response == "password");
257 sendAuthenticationComplete();
260void Greeter::sendAuthenticationComplete()
262 if (qgetenv("UNITY_TESTING").isEmpty()) {
263 // simulate PAM's delay
264 QTimer::singleShot(1000, this, &Greeter::authenticationComplete);
266 Q_EMIT authenticationComplete();
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