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
21import Ubuntu.Components 1.3
22import Ubuntu.SystemImage 0.1
23import Unity.Launcher 0.1
24import Unity.Session 0.1
29 created: loader.status == Loader.Ready
31 property real dragHandleLeftMargin: 0
33 property url background
35 // How far to offset the top greeter layer during a launcher left-drag
36 property real launcherOffset
38 readonly property bool active: required || hasLockedApp
39 readonly property bool fullyShown: loader.item ? loader.item.fullyShown : false
41 // True when the greeter is waiting for PAM or other setup process
42 readonly property alias waiting: d.waiting
44 property string lockedApp: ""
45 readonly property bool hasLockedApp: lockedApp !== ""
47 property bool forcedUnlock
48 readonly property bool locked: lightDM.greeter.active && !lightDM.greeter.authenticated && !forcedUnlock
50 property bool tabletMode
51 property url viewSource // only used for testing
53 property int maxFailedLogins: -1 // disabled by default for now, will enable via settings in future
54 property int failedLoginsDelayAttempts: 7 // number of failed logins
55 property real failedLoginsDelayMinutes: 5 // minutes of forced waiting
57 readonly property bool animating: loader.item ? loader.item.animating : false
60 signal sessionStarted()
61 signal emergencyCall()
63 function forceShow() {
66 d.selectUser(d.currentIndex, true);
69 function notifyAppFocusRequested(appId) {
75 if (appId === lockedApp) {
76 hide(); // show locked app
79 d.startUnlock(false /* toTheRight */);
81 } else if (appId !== "unity8-dash") { // dash isn't started by user
82 d.startUnlock(false /* toTheRight */);
86 // Notify that the user has explicitly requested the given app through unity8 GUI.
87 function notifyUserRequestedApp(appId) {
92 // A hint that we're about to focus an app. This way we can look
93 // a little more responsive, rather than waiting for the above
94 // notifyAppFocusRequested call. We also need this in case we have a locked
95 // app, in order to show lockscreen instead of new app.
96 d.startUnlock(false /* toTheRight */);
99 // This is a just a glorified notifyUserRequestedApp(), but it does one
100 // other thing: it hides any cover pages to the RIGHT, because the user
101 // just came from a launcher drag starting on the left.
102 // It also returns a boolean value, indicating whether there was a visual
103 // change or not (the shell only wants to hide the launcher if there was
105 function notifyShowingDashFromDrag() {
110 return d.startUnlock(true /* toTheRight */);
113 LightDM{id:lightDM} // Provide backend access
117 readonly property bool multiUser: lightDM.users.count > 1
118 property int currentIndex
119 property bool waiting
120 property int fingerprintFailureCount
122 // We want 'launcherOffset' to animate down to zero. But not to animate
123 // while being dragged. So ideally we change this only when the user
124 // lets go and launcherOffset drops to zero. But we need to wait for
125 // the behavior to be enabled first. So we cache the last known good
126 // launcherOffset value to cover us during that brief gap between
127 // release and the behavior turning on.
128 property real lastKnownPositiveOffset // set in a launcherOffsetChanged below
129 property real launcherOffsetProxy: (shown && !launcherOffsetProxyBehavior.enabled) ? lastKnownPositiveOffset : 0
130 Behavior on launcherOffsetProxy {
131 id: launcherOffsetProxyBehavior
132 enabled: launcherOffset === 0
133 UbuntuNumberAnimation {}
136 onFingerprintFailureCountChanged: {
137 if (d.fingerprintFailureCount >= 3) {
138 d.startUnlock(false /* toTheRight */);
139 d.fingerprintFailureCount = 0;
143 function selectUser(uid, reset) {
145 d.fingerprintFailureCount = 0;
150 var user = lightDM.users.data(uid, lightDM.userRoles.NameRole);
151 AccountsService.user = user;
152 LauncherModel.setUser(user);
153 lightDM.greeter.authenticate(user); // always resets auth state
158 if (lightDM.greeter.startSessionSync()) {
161 loader.item.notifyAuthenticationSucceeded(false /* showFakePassword */);
163 } else if (loader.item) {
164 loader.item.notifyAuthenticationFailed();
169 function startUnlock(toTheRight) {
171 return loader.item.tryToUnlock(toTheRight);
177 function checkForcedUnlock() {
178 if (forcedUnlock && shown && loader.item) {
179 // pretend we were just authenticated
180 loader.item.notifyAuthenticationSucceeded(false /* showFakePassword */);
186 onLauncherOffsetChanged: {
187 if (launcherOffset > 0) {
188 d.lastKnownPositiveOffset = launcherOffset;
192 onForcedUnlockChanged: d.checkForcedUnlock()
193 Component.onCompleted: d.checkForcedUnlock()
204 schema.id: "com.canonical.Unity8.Greeter"
210 // We use a short interval and check against the system wall clock
211 // because we have to consider the case that the system is suspended
212 // for a few minutes. When we wake up, we want to quickly be correct.
215 property var delayTarget
216 property int delayMinutes
218 function forceDelay() {
219 // Store the beginning time for a lockout in GSettings, so that
220 // we still lock the user out if they reboot. And we store
221 // starting time rather than end-time or how-long because:
222 // - If storing end-time and on boot we have a problem with NTP,
223 // we might get locked out for a lot longer than we thought.
224 // - If storing how-long, and user turns their phone off for an
225 // hour rather than wait, they wouldn't expect to still be locked
227 // - A malicious actor could manipulate either of the above
228 // settings to keep the user out longer. But by storing
229 // start-time, we never make the user wait longer than the full
231 greeterSettings.lockedOutTime = new Date().getTime();
232 checkForForcedDelay();
236 var diff = delayTarget - new Date();
238 delayMinutes = Math.ceil(diff / 60000);
245 function checkForForcedDelay() {
246 if (greeterSettings.lockedOutTime === 0) {
250 var now = new Date();
251 delayTarget = new Date(greeterSettings.lockedOutTime + failedLoginsDelayMinutes * 60000);
253 // If tooEarly is true, something went very wrong. Bug or NTP
254 // misconfiguration maybe?
255 var tooEarly = now.getTime() < greeterSettings.lockedOutTime;
256 var tooLate = now >= delayTarget;
258 // Compare stored time to system time. If a malicious actor is
259 // able to manipulate time to avoid our lockout, they already have
260 // enough access to cause damage. So we choose to trust this check.
261 if (tooEarly || tooLate) {
269 Component.onCompleted: checkForForcedDelay()
273 // Nothing should leak to items behind the greeter
274 MouseArea { anchors.fill: parent; hoverEnabled: true }
282 active: root.required
283 source: root.viewSource.toString() ? root.viewSource :
284 (d.multiUser || root.tabletMode) ? "WideView.qml" : "NarrowView.qml"
288 root.forceActiveFocus();
289 d.selectUser(d.currentIndex, true);
290 lightDM.infographic.readyForDataChange();
296 d.selectUser(index, true);
300 lightDM.greeter.respond(response);
302 if (lightDM.greeter.active && !lightDM.greeter.authenticated) { // could happen if forcedUnlock
308 onTease: root.tease()
309 onEmergencyCall: root.emergencyCall()
311 if (!loader.item.required) {
319 property: "backgroundTopMargin"
325 property: "launcherOffset"
326 value: d.launcherOffsetProxy
331 property: "dragHandleLeftMargin"
332 value: root.dragHandleLeftMargin
337 property: "delayMinutes"
338 value: forcedDelayTimer.delayMinutes
343 property: "background"
344 value: root.background
355 property: "alphanumeric"
356 value: AccountsService.passwordDisplayHint === AccountsService.Keyboard
361 property: "currentIndex"
362 value: d.currentIndex
367 property: "userModel"
373 property: "infographicModel"
374 value: lightDM.infographic
379 target: lightDM.greeter
381 onShowGreeter: root.forceShow()
389 if (!lightDM.greeter.active) {
390 return; // could happen if hideGreeter() comes in before we prompt
393 // inefficient, but we only rarely deal with messages
394 var html = text.replace(/&/g, "&")
395 .replace(/</g, "<")
396 .replace(/>/g, ">")
397 .replace(/\n/g, "<br>");
399 html = "<font color=\"#df382c\">" + html + "</font>";
402 loader.item.showMessage(html);
408 if (!lightDM.greeter.active) {
409 return; // could happen if hideGreeter() comes in before we prompt
412 loader.item.showPrompt(text, isSecret, isDefaultPrompt);
415 onAuthenticationComplete: {
418 if (lightDM.greeter.authenticated) {
419 AccountsService.failedLogins = 0;
421 if (!lightDM.greeter.promptless) {
425 if (!lightDM.greeter.promptless) {
426 AccountsService.failedLogins++;
429 // Check if we should initiate a factory reset
430 if (maxFailedLogins >= 2) { // require at least a warning
431 if (AccountsService.failedLogins === maxFailedLogins - 1) {
432 loader.item.showLastChance();
433 } else if (AccountsService.failedLogins >= maxFailedLogins) {
434 SystemImage.factoryReset(); // Ouch!
438 // Check if we should initiate a forced login delay
439 if (failedLoginsDelayAttempts > 0
440 && AccountsService.failedLogins > 0
441 && AccountsService.failedLogins % failedLoginsDelayAttempts == 0) {
442 forcedDelayTimer.forceDelay();
445 loader.item.notifyAuthenticationFailed();
446 if (!lightDM.greeter.promptless) {
447 d.selectUser(d.currentIndex, false);
452 onRequestAuthenticationUser: {
453 // Find index for requested user, if it exists
454 for (var i = 0; i < lightDM.users.count; i++) {
455 if (user === lightDM.users.data(i, lightDM.userRoles.NameRole)) {
456 d.selectUser(i, true);
464 target: DBusUnitySessionService
465 onLockRequested: root.forceShow()
469 target: lightDM.greeter
475 target: lightDM.infographic
477 value: AccountsService.statsWelcomeScreen ? lightDM.users.data(d.currentIndex, lightDM.userRoles.NameRole) : ""
482 onLanguageChanged: lightDM.infographic.readyForDataChange()
487 objectName: "biometryd"
489 property var operation: null
490 readonly property bool idEnabled: root.active &&
491 Biometryd.defaultDevice &&
492 AccountsService.enableFingerprintIdentification
494 function cancelOperation() {
501 function restartOperation() {
505 var identifier = Biometryd.defaultDevice.identifier;
506 operation = identifier.identifyUser();
507 operation.start(biometryd);
511 function failOperation(reason) {
512 console.log("Failed to identify user by fingerprint:", reason);
513 d.fingerprintFailureCount++;
516 loader.item.showErrorMessage(i18n.tr("Try again"));
519 Component.onCompleted: restartOperation()
520 Component.onDestruction: cancelOperation()
521 onIdEnabledChanged: restartOperation()
524 if (result.uid !== lightDM.users.data(d.currentIndex, lightDM.userRoles.UidRole)) {
525 failOperation("not the selected user");
528 console.log("Identified user by fingerprint:", result.uid);
529 d.fingerprintFailureCount = 0;
531 loader.item.notifyAuthenticationSucceeded(true /* showFakePassword */);
533 root.forcedUnlock = true;
535 onFailed: failOperation(reason)
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