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/>.
18import AccountsService 0.1
20import LightDM 0.1 as LightDM
21import Ubuntu.Components 1.1
22import Ubuntu.SystemImage 0.1
23import Unity.Launcher 0.1
28 created: loader.status == Loader.Ready
30 property real dragHandleLeftMargin: 0
32 property url background
34 // How far to offset the top greeter layer during a launcher left-drag
35 property real launcherOffset
37 readonly property bool active: shown || hasLockedApp
38 readonly property bool fullyShown: loader.item ? loader.item.fullyShown : false
40 // True when the greeter is waiting for PAM or other setup process
41 readonly property alias waiting: d.waiting
43 property string lockedApp: ""
44 readonly property bool hasLockedApp: lockedApp !== ""
46 property bool forcedUnlock
47 readonly property bool locked: LightDM.Greeter.active && !LightDM.Greeter.authenticated && !forcedUnlock
49 property bool tabletMode
50 property url viewSource // only used for testing
52 property int maxFailedLogins: -1 // disabled by default for now, will enable via settings in future
53 property int failedLoginsDelayAttempts: 7 // number of failed logins
54 property real failedLoginsDelayMinutes: 5 // minutes of forced waiting
56 readonly property bool animating: loader.item ? loader.item.animating : false
59 signal sessionStarted()
60 signal emergencyCall()
62 function forceShow() {
67 function notifyAppFocused(appId) {
73 if (appId === lockedApp) {
74 hide(); // show locked app
77 d.startUnlock(false /* toTheRight */);
79 } else if (appId !== "unity8-dash") { // dash isn't started by user
80 d.startUnlock(false /* toTheRight */);
84 function notifyAboutToFocusApp(appId) {
89 // A hint that we're about to focus an app. This way we can look
90 // a little more responsive, rather than waiting for the above
91 // notifyAppFocused call. We also need this in case we have a locked
92 // app, in order to show lockscreen instead of new app.
93 d.startUnlock(false /* toTheRight */);
96 // This is a just a glorified notifyAboutToFocusApp(), but it does one
97 // other thing: it hides any cover pages to the RIGHT, because the user
98 // just came from a launcher drag starting on the left.
99 // It also returns a boolean value, indicating whether there was a visual
100 // change or not (the shell only wants to hide the launcher if there was
102 function notifyShowingDashFromDrag() {
107 return d.startUnlock(true /* toTheRight */);
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"
188 onLockedOutTimeChanged: forcedDelayTimer.checkForForcedDelay()
194 // We use a short interval and check against the system wall clock
195 // because we have to consider the case that the system is suspended
196 // for a few minutes. When we wake up, we want to quickly be correct.
199 property var delayTarget;
200 property int delayMinutes;
202 function forceDelay() {
203 // Store the beginning time for a lockout in GSettings, so that
204 // we still lock the user out if they reboot. And we store
205 // starting time rather than end-time or how-long because:
206 // - If storing end-time and on boot we have a problem with NTP,
207 // we might get locked out for a lot longer than we thought.
208 // - If storing how-long, and user turns their phone off for an
209 // hour rather than wait, they wouldn't expect to still be locked
211 // - A malicious actor could manipulate either of the above
212 // settings to keep the user out longer. But by storing
213 // start-time, we never make the user wait longer than the full
215 // The code below that watches GSettings will pick up the change
217 greeterSettings.lockedOutTime = new Date().getTime();
221 var diff = delayTarget - new Date();
223 delayMinutes = Math.ceil(diff / 60000);
230 function checkForForcedDelay() {
231 var now = new Date();
233 delayTarget.setTime(greeterSettings.lockedOutTime + failedLoginsDelayMinutes * 60000);
235 // If tooEarly is true, something went very wrong. Bug or NTP
236 // misconfiguration maybe?
237 var tooEarly = now.getTime() < greeterSettings.lockedOutTime;
238 var tooLate = now > delayTarget;
240 // Compare stored time to system time. If a malicious actor is
241 // able to manipulate time to avoid our lockout, they already have
242 // enough access to cause damage. So we choose to trust this check.
243 if (tooEarly || tooLate) {
251 Component.onCompleted: checkForForcedDelay()
255 // Nothing should leak to items behind the greeter
256 MouseArea { anchors.fill: parent }
264 active: root.required
265 source: root.viewSource.toString() ? root.viewSource :
266 (d.multiUser || root.tabletMode) ? "WideView.qml" : "NarrowView.qml"
270 root.forceActiveFocus();
271 d.selectUser(d.currentIndex, true);
272 LightDM.Infographic.readyForDataChange();
278 d.selectUser(index, true);
282 LightDM.Greeter.respond(response);
284 if (LightDM.Greeter.active && !LightDM.Greeter.authenticated) { // could happen if forcedUnlock
290 onTease: root.tease()
291 onEmergencyCall: root.emergencyCall()
293 if (!loader.item.required) {
301 property: "backgroundTopMargin"
307 property: "launcherOffset"
308 value: d.launcherOffsetProxy
313 property: "dragHandleLeftMargin"
314 value: root.dragHandleLeftMargin
319 property: "delayMinutes"
320 value: forcedDelayTimer.delayMinutes
325 property: "background"
326 value: root.background
337 property: "alphanumeric"
338 value: AccountsService.passwordDisplayHint === AccountsService.Keyboard
343 property: "currentIndex"
344 value: d.currentIndex
349 property: "userModel"
355 property: "infographicModel"
356 value: LightDM.Infographic
361 target: LightDM.Greeter
363 onShowGreeter: root.forceShow()
371 if (!LightDM.Greeter.active) {
372 return; // could happen if hideGreeter() comes in before we prompt
375 // inefficient, but we only rarely deal with messages
376 var html = text.replace(/&/g, "&")
377 .replace(/</g, "<")
378 .replace(/>/g, ">")
379 .replace(/\n/g, "<br>");
381 html = "<font color=\"#df382c\">" + html + "</font>";
384 loader.item.showMessage(html);
390 if (!LightDM.Greeter.active) {
391 return; // could happen if hideGreeter() comes in before we prompt
394 loader.item.showPrompt(text, isSecret, isDefaultPrompt);
397 onAuthenticationComplete: {
400 if (LightDM.Greeter.authenticated) {
401 AccountsService.failedLogins = 0;
403 if (!LightDM.Greeter.promptless) {
407 if (!LightDM.Greeter.promptless) {
408 AccountsService.failedLogins++;
411 // Check if we should initiate a factory reset
412 if (maxFailedLogins >= 2) { // require at least a warning
413 if (AccountsService.failedLogins === maxFailedLogins - 1) {
414 loader.item.showLastChance();
415 } else if (AccountsService.failedLogins >= maxFailedLogins) {
416 SystemImage.factoryReset(); // Ouch!
420 // Check if we should initiate a forced login delay
421 if (failedLoginsDelayAttempts > 0
422 && AccountsService.failedLogins > 0
423 && AccountsService.failedLogins % failedLoginsDelayAttempts == 0) {
424 forcedDelayTimer.forceDelay();
427 loader.item.notifyAuthenticationFailed();
428 if (!LightDM.Greeter.promptless) {
429 d.selectUser(d.currentIndex, false);
434 onRequestAuthenticationUser: {
435 // Find index for requested user, if it exists
436 for (var i = 0; i < LightDM.Users.count; i++) {
437 if (user === LightDM.Users.data(i, LightDM.UserRoles.NameRole)) {
438 d.selectUser(i, true);
446 target: LightDM.Greeter
452 target: LightDM.Infographic
454 value: AccountsService.statsWelcomeScreen ? LightDM.Users.data(d.currentIndex, LightDM.UserRoles.NameRole) : ""
459 onLanguageChanged: LightDM.Infographic.readyForDataChange()
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