14
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#include "GreeterPrivate.h"
19
#include <QtCore/QCoreApplication>
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;
32
QTimer authCallbackTimer;
25
35
Greeter::Greeter(QObject *parent)
27
d_ptr(new GreeterPrivate(this))
37
, d_ptr(new GreeterPrivate)
41
d->authCallbackTimer.setSingleShot(true);
42
connect(&d->authCallbackTimer, &QTimer::timeout,
43
this, &QLightDM::Greeter::handleAuthenticate);
31
46
Greeter::~Greeter()
35
51
QString Greeter::authenticationUser() const
37
53
Q_D(const Greeter);
38
55
return d->authenticationUser;
41
58
bool Greeter::hasGuestAccountHint() const
60
return MockController::instance()->hasGuestAccountHint();
46
63
QString Greeter::getHint(const QString &name) const
57
74
bool Greeter::hideUsersHint() const
76
return MockController::instance()->hideUsersHint();
62
79
bool Greeter::showManualLoginHint() const
81
return MockController::instance()->showManualLoginHint();
67
84
bool Greeter::showRemoteLoginHint() const
72
89
QString Greeter::selectUserHint() const
75
return d->selectUserHint;
78
void Greeter::setSelectUserHint(const QString &selectUserHint)
81
d->selectUserHint = selectUserHint;
91
return MockController::instance()->selectUserHint();
84
94
bool Greeter::selectGuestHint() const
96
return MockController::instance()->selectGuestHint();
89
99
QString Greeter::autologinUserHint() const
129
140
d->authenticated = false;
130
141
d->authenticationUser = username;
131
142
d->twoFactorDone = false;
132
QTimer::singleShot(0, this, &Greeter::delayedAuthentication);
143
d->authCallbackTimer.start();
135
void Greeter::delayedAuthentication()
146
void Greeter::handleAuthenticate()
138
d->handleAuthenticate();
150
if (d->authenticated) {
151
// This can happen from the guest authentication flow
152
Q_EMIT authenticationComplete();
156
if (d->authenticationUser.isEmpty()) {
157
Q_EMIT showPrompt("Username: ", Greeter::PromptTypeQuestion);
161
// Send out any messages we need to
162
if (d->authenticationUser == "info-prompt")
163
Q_EMIT showMessage("Welcome to Unity Greeter", Greeter::MessageTypeInfo);
164
else if (d->authenticationUser == "wide-info-prompt")
165
Q_EMIT showMessage("Welcome to Unity Greeter, the greeteriest greeter that ever did appear in these fine lands", Greeter::MessageTypeInfo);
166
else if (d->authenticationUser == "html-info-prompt")
167
Q_EMIT showMessage("<b>&</b>", Greeter::MessageTypeInfo);
168
else if (d->authenticationUser == "long-info-prompt")
169
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);
170
else if (d->authenticationUser == "multi-info-prompt") {
171
Q_EMIT showMessage("Welcome to Unity Greeter", Greeter::MessageTypeInfo);
172
Q_EMIT showMessage("This is an error", Greeter::MessageTypeError);
173
Q_EMIT showMessage("You should have seen three messages", Greeter::MessageTypeInfo);
176
// OK, now actually do the prompt
177
if (d->authenticationUser == "no-password") {
178
d->authenticated = true;
179
Q_EMIT authenticationComplete();
180
} else if (d->authenticationUser == "has-pin") {
181
Q_EMIT showPrompt("Password: ", Greeter::PromptTypeSecret);
182
} else if (d->authenticationUser == "auth-error") {
183
d->authenticated = false;
184
Q_EMIT authenticationComplete();
185
} else if (d->authenticationUser == "different-prompt") {
186
Q_EMIT showPrompt("Secret word: ", Greeter::PromptTypeSecret);
187
} else if (d->authenticationUser == "question-prompt") {
188
Q_EMIT showPrompt("Favorite Color (blue): ", Greeter::PromptTypeQuestion);
189
} else if (d->authenticationUser == "two-prompts") {
190
Q_EMIT showPrompt("Favorite Color (blue):", Greeter::PromptTypeQuestion);
191
Q_EMIT showPrompt("Password: ", Greeter::PromptTypeSecret);
192
} else if (d->authenticationUser == "wacky-prompts") {
193
Q_EMIT showMessage("First message", Greeter::MessageTypeInfo);
194
Q_EMIT showPrompt("Favorite Color (blue)", Greeter::PromptTypeQuestion);
195
Q_EMIT showMessage("Second message", Greeter::MessageTypeError);
196
Q_EMIT showPrompt("Password: ", Greeter::PromptTypeSecret);
197
Q_EMIT showMessage("Last message", Greeter::MessageTypeInfo);
199
Q_EMIT showPrompt("Password: ", Greeter::PromptTypeSecret);
141
203
void Greeter::authenticateAsGuest()
207
d->authenticated = true;
208
d->authenticationUser = QString(); // this is what the real liblightdm does
209
d->twoFactorDone = false;
210
d->authCallbackTimer.start();
144
213
void Greeter::authenticateAutologin()
161
233
bool Greeter::startSessionSync(const QString &session)
163
235
Q_UNUSED(session)
237
// Send a request to hide the greeter. This is normally done by logind,
238
// but when testing, we don't want the bother of mocking that out. Instead,
239
// just send the request directly ourselves.
240
QDBusInterface iface("com.canonical.UnityGreeter",
242
"com.canonical.UnityGreeter",
243
QDBusConnection::sessionBus());
244
iface.asyncCall("HideGreeter");
171
d->handleRespond(response);
253
if (d->authenticationUser.isEmpty()) {
254
// A manual login, our first question was which username
255
d->authenticationUser = response;
256
handleAuthenticate();
260
if (d->authenticationUser == "no-response") {
262
} else if (d->authenticationUser == "locked") {
263
Q_EMIT showMessage("Account is locked", Greeter::MessageTypeError);
264
sendAuthenticationComplete();
266
} else if (d->authenticationUser == "two-factor") {
267
if (!d->twoFactorDone) {
268
if (response == "password") {
269
d->twoFactorDone = true;
270
Q_EMIT showPrompt("otp", Greeter::PromptTypeQuestion);
272
d->authenticated = false;
273
sendAuthenticationComplete();
276
d->authenticated = (response == "otp");
277
sendAuthenticationComplete();
280
} else if (d->authenticationUser == "two-prompts" || d->authenticationUser == "wacky-prompts") {
281
if (!d->twoFactorDone) {
282
d->authenticated = (response == "blue");
283
d->twoFactorDone = true;
285
d->authenticated = d->authenticated && (response == "password");
286
sendAuthenticationComplete();
291
if (d->authenticationUser == "has-pin") {
292
d->authenticated = (response == "1234");
293
} else if (d->authenticationUser == "question-prompt") {
294
d->authenticated = (response == "blue");
296
d->authenticated = (response == "password");
299
if (d->authenticationUser == "info-after-login" && d->authenticated) {
300
Q_EMIT showMessage("Congratulations on logging in!", Greeter::MessageTypeInfo);
303
sendAuthenticationComplete();
174
306
void Greeter::sendAuthenticationComplete()