2 * Copyright (C) 2013,2014,2015 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/>.
18 import AccountsService 0.1
20 import Ubuntu.Components 1.3
21 import Ubuntu.SystemImage 0.1
22 import Unity.Launcher 0.1
23 import "../Components"
27 created: loader.status == Loader.Ready
29 property real dragHandleLeftMargin: 0
31 property url background
33 // How far to offset the top greeter layer during a launcher left-drag
34 property real launcherOffset
36 readonly property bool active: shown || hasLockedApp
37 readonly property bool fullyShown: loader.item ? loader.item.fullyShown : false
39 // True when the greeter is waiting for PAM or other setup process
40 readonly property alias waiting: d.waiting
42 property string lockedApp: ""
43 readonly property bool hasLockedApp: lockedApp !== ""
45 property bool forcedUnlock
46 readonly property bool locked: lightDM.greeter.active && !lightDM.greeter.authenticated && !forcedUnlock
48 property bool tabletMode
49 property url viewSource // only used for testing
51 property int maxFailedLogins: -1 // disabled by default for now, will enable via settings in future
52 property int failedLoginsDelayAttempts: 7 // number of failed logins
53 property real failedLoginsDelayMinutes: 5 // minutes of forced waiting
55 readonly property bool animating: loader.item ? loader.item.animating : false
58 signal sessionStarted()
59 signal emergencyCall()
61 function forceShow() {
66 function notifyAppFocused(appId) {
72 if (appId === lockedApp) {
73 hide(); // show locked app
76 d.startUnlock(false /* toTheRight */);
78 } else if (appId !== "unity8-dash") { // dash isn't started by user
79 d.startUnlock(false /* toTheRight */);
83 function notifyAboutToFocusApp(appId) {
88 // A hint that we're about to focus an app. This way we can look
89 // a little more responsive, rather than waiting for the above
90 // notifyAppFocused call. We also need this in case we have a locked
91 // app, in order to show lockscreen instead of new app.
92 d.startUnlock(false /* toTheRight */);
95 // This is a just a glorified notifyAboutToFocusApp(), but it does one
96 // other thing: it hides any cover pages to the RIGHT, because the user
97 // just came from a launcher drag starting on the left.
98 // It also returns a boolean value, indicating whether there was a visual
99 // change or not (the shell only wants to hide the launcher if there was
101 function notifyShowingDashFromDrag() {
106 return d.startUnlock(true /* toTheRight */);
109 LightDM{id:lightDM} // Provide backend access
113 readonly property bool multiUser: lightDM.users.count > 1
114 property int currentIndex
115 property bool waiting
117 // We want 'launcherOffset' to animate down to zero. But not to animate
118 // while being dragged. So ideally we change this only when the user
119 // lets go and launcherOffset drops to zero. But we need to wait for
120 // the behavior to be enabled first. So we cache the last known good
121 // launcherOffset value to cover us during that brief gap between
122 // release and the behavior turning on.
123 property real lastKnownPositiveOffset // set in a launcherOffsetChanged below
124 property real launcherOffsetProxy: (shown && !launcherOffsetProxyBehavior.enabled) ? lastKnownPositiveOffset : 0
125 Behavior on launcherOffsetProxy {
126 id: launcherOffsetProxyBehavior
127 enabled: launcherOffset === 0
128 UbuntuNumberAnimation {}
131 function selectUser(uid, reset) {
137 var user = lightDM.users.data(uid, lightDM.userRoles.NameRole);
138 AccountsService.user = user;
139 LauncherModel.setUser(user);
140 lightDM.greeter.authenticate(user); // always resets auth state
145 if (lightDM.greeter.startSessionSync()) {
148 loader.item.notifyAuthenticationSucceeded();
150 } else if (loader.item) {
151 loader.item.notifyAuthenticationFailed();
156 function startUnlock(toTheRight) {
158 return loader.item.tryToUnlock(toTheRight);
165 onLauncherOffsetChanged: {
166 if (launcherOffset > 0) {
167 d.lastKnownPositiveOffset = launcherOffset;
171 onForcedUnlockChanged: {
172 if (forcedUnlock && shown) {
173 // pretend we were just authenticated
174 loader.item.notifyAuthenticationSucceeded();
187 schema.id: "com.canonical.Unity8.Greeter"
193 // We use a short interval and check against the system wall clock
194 // because we have to consider the case that the system is suspended
195 // for a few minutes. When we wake up, we want to quickly be correct.
198 property var delayTarget
199 property int delayMinutes
201 function forceDelay() {
202 // Store the beginning time for a lockout in GSettings, so that
203 // we still lock the user out if they reboot. And we store
204 // starting time rather than end-time or how-long because:
205 // - If storing end-time and on boot we have a problem with NTP,
206 // we might get locked out for a lot longer than we thought.
207 // - If storing how-long, and user turns their phone off for an
208 // hour rather than wait, they wouldn't expect to still be locked
210 // - A malicious actor could manipulate either of the above
211 // settings to keep the user out longer. But by storing
212 // start-time, we never make the user wait longer than the full
214 greeterSettings.lockedOutTime = new Date().getTime();
215 checkForForcedDelay();
219 var diff = delayTarget - new Date();
221 delayMinutes = Math.ceil(diff / 60000);
228 function checkForForcedDelay() {
229 var now = new Date();
231 delayTarget.setTime(greeterSettings.lockedOutTime + failedLoginsDelayMinutes * 60000);
233 // If tooEarly is true, something went very wrong. Bug or NTP
234 // misconfiguration maybe?
235 var tooEarly = now.getTime() < greeterSettings.lockedOutTime;
236 var tooLate = now > delayTarget;
238 // Compare stored time to system time. If a malicious actor is
239 // able to manipulate time to avoid our lockout, they already have
240 // enough access to cause damage. So we choose to trust this check.
241 if (tooEarly || tooLate) {
249 Component.onCompleted: checkForForcedDelay()
253 // Nothing should leak to items behind the greeter
254 MouseArea { anchors.fill: parent; hoverEnabled: true }
262 active: root.required
263 source: root.viewSource.toString() ? root.viewSource :
264 (d.multiUser || root.tabletMode) ? "WideView.qml" : "NarrowView.qml"
268 root.forceActiveFocus();
269 d.selectUser(d.currentIndex, true);
270 lightDM.infographic.readyForDataChange();
276 d.selectUser(index, true);
280 lightDM.greeter.respond(response);
282 if (lightDM.greeter.active && !lightDM.greeter.authenticated) { // could happen if forcedUnlock
288 onTease: root.tease()
289 onEmergencyCall: root.emergencyCall()
291 if (!loader.item.required) {
299 property: "backgroundTopMargin"
305 property: "launcherOffset"
306 value: d.launcherOffsetProxy
311 property: "dragHandleLeftMargin"
312 value: root.dragHandleLeftMargin
317 property: "delayMinutes"
318 value: forcedDelayTimer.delayMinutes
323 property: "background"
324 value: root.background
335 property: "alphanumeric"
336 value: AccountsService.passwordDisplayHint === AccountsService.Keyboard
341 property: "currentIndex"
342 value: d.currentIndex
347 property: "userModel"
353 property: "infographicModel"
354 value: lightDM.infographic
359 target: lightDM.greeter
361 onShowGreeter: root.forceShow()
369 if (!lightDM.greeter.active) {
370 return; // could happen if hideGreeter() comes in before we prompt
373 // inefficient, but we only rarely deal with messages
374 var html = text.replace(/&/g, "&")
375 .replace(/</g, "<")
376 .replace(/>/g, ">")
377 .replace(/\n/g, "<br>");
379 html = "<font color=\"#df382c\">" + html + "</font>";
382 loader.item.showMessage(html);
388 if (!lightDM.greeter.active) {
389 return; // could happen if hideGreeter() comes in before we prompt
392 loader.item.showPrompt(text, isSecret, isDefaultPrompt);
395 onAuthenticationComplete: {
398 if (lightDM.greeter.authenticated) {
399 AccountsService.failedLogins = 0;
401 if (!lightDM.greeter.promptless) {
405 if (!lightDM.greeter.promptless) {
406 AccountsService.failedLogins++;
409 // Check if we should initiate a factory reset
410 if (maxFailedLogins >= 2) { // require at least a warning
411 if (AccountsService.failedLogins === maxFailedLogins - 1) {
412 loader.item.showLastChance();
413 } else if (AccountsService.failedLogins >= maxFailedLogins) {
414 SystemImage.factoryReset(); // Ouch!
418 // Check if we should initiate a forced login delay
419 if (failedLoginsDelayAttempts > 0
420 && AccountsService.failedLogins > 0
421 && AccountsService.failedLogins % failedLoginsDelayAttempts == 0) {
422 forcedDelayTimer.forceDelay();
425 loader.item.notifyAuthenticationFailed();
426 if (!lightDM.greeter.promptless) {
427 d.selectUser(d.currentIndex, false);
432 onRequestAuthenticationUser: {
433 // Find index for requested user, if it exists
434 for (var i = 0; i < lightDM.users.count; i++) {
435 if (user === lightDM.users.data(i, lightDM.userRoles.NameRole)) {
436 d.selectUser(i, true);
444 target: lightDM.greeter
450 target: lightDM.infographic
452 value: AccountsService.statsWelcomeScreen ? lightDM.users.data(d.currentIndex, lightDM.userRoles.NameRole) : ""
457 onLanguageChanged: lightDM.infographic.readyForDataChange()