2024-06-26 02:57:42 +00:00
|
|
|
// SPDX-FileCopyrightText: 2022-2024 Devin Lin <devin@kde.org>
|
2022-06-18 20:47:41 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2022-05-21 03:41:11 +00:00
|
|
|
|
2023-05-13 15:15:52 +00:00
|
|
|
import QtQml
|
|
|
|
|
import QtQuick
|
2022-05-21 03:41:11 +00:00
|
|
|
|
2024-02-11 23:03:17 +00:00
|
|
|
import org.kde.kscreenlocker 1.0 as ScreenLocker
|
2023-10-28 18:44:06 +00:00
|
|
|
|
2022-05-21 03:41:11 +00:00
|
|
|
QtObject {
|
|
|
|
|
id: root
|
2024-06-26 02:57:42 +00:00
|
|
|
|
2022-05-21 03:41:11 +00:00
|
|
|
// current password being typed
|
|
|
|
|
property string password: ""
|
2024-06-26 02:57:42 +00:00
|
|
|
|
2022-05-21 03:41:11 +00:00
|
|
|
// whether waiting for authentication after trying password
|
|
|
|
|
property bool waitingForAuth: false
|
2024-06-26 02:57:42 +00:00
|
|
|
|
2022-06-18 20:47:41 +00:00
|
|
|
// the info message given
|
2022-05-21 03:41:11 +00:00
|
|
|
property string info: ""
|
2024-06-26 02:57:42 +00:00
|
|
|
|
2024-07-03 02:10:29 +00:00
|
|
|
// whether the lockscreen can be unlocked (no password needed, passwordless login)
|
|
|
|
|
readonly property bool canBeUnlocked: authenticator.unlocked
|
2024-06-26 02:57:42 +00:00
|
|
|
|
2024-06-16 20:50:06 +00:00
|
|
|
// whether the device can log in with fingerprint
|
2024-02-11 23:03:17 +00:00
|
|
|
readonly property bool isFingerprintSupported: authenticator.authenticatorTypes & ScreenLocker.Authenticator.Fingerprint
|
2023-10-28 18:44:06 +00:00
|
|
|
|
2024-06-26 02:57:42 +00:00
|
|
|
// whether we are in keyboard mode (hiding the numpad)
|
|
|
|
|
property bool isKeyboardMode: false
|
|
|
|
|
|
|
|
|
|
property string pinLabel: enterPinLabel
|
|
|
|
|
readonly property string enterPinLabel: i18n("Enter PIN")
|
|
|
|
|
readonly property string wrongPinLabel: i18n("Wrong PIN")
|
|
|
|
|
|
2022-05-21 03:41:11 +00:00
|
|
|
signal reset()
|
|
|
|
|
signal unlockSucceeded()
|
|
|
|
|
signal unlockFailed()
|
2024-06-26 02:57:42 +00:00
|
|
|
|
|
|
|
|
Component.onCompleted: authenticator.startAuthenticating();
|
|
|
|
|
|
2022-05-21 03:41:11 +00:00
|
|
|
function tryPassword() {
|
2024-07-03 02:10:29 +00:00
|
|
|
// ensure it's in authenticating state (it might get unset after suspend)
|
|
|
|
|
authenticator.startAuthenticating();
|
|
|
|
|
|
|
|
|
|
// prevent typing lock when password is empty
|
|
|
|
|
if (root.password !== '') {
|
2024-06-26 02:57:42 +00:00
|
|
|
root.waitingForAuth = true;
|
2022-05-21 03:41:11 +00:00
|
|
|
}
|
2024-07-03 02:10:29 +00:00
|
|
|
console.log('attempt password');
|
2024-06-26 02:57:42 +00:00
|
|
|
authenticator.respond(root.password);
|
2022-05-21 03:41:11 +00:00
|
|
|
}
|
2024-06-26 02:57:42 +00:00
|
|
|
|
2022-05-21 03:41:11 +00:00
|
|
|
function resetPassword() {
|
|
|
|
|
password = "";
|
|
|
|
|
root.reset();
|
|
|
|
|
}
|
2024-06-26 02:57:42 +00:00
|
|
|
|
|
|
|
|
function resetPinLabel(): void {
|
|
|
|
|
pinLabel = enterPinLabel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
property var graceLockTimer: Timer {
|
2026-01-19 03:39:16 +00:00
|
|
|
interval: 3000
|
2024-06-26 02:57:42 +00:00
|
|
|
onTriggered: {
|
|
|
|
|
root.waitingForAuth = false;
|
|
|
|
|
root.password = "";
|
|
|
|
|
authenticator.startAuthenticating();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-21 03:41:11 +00:00
|
|
|
property var connections: Connections {
|
|
|
|
|
target: authenticator
|
2024-06-26 02:57:42 +00:00
|
|
|
|
2022-05-21 03:41:11 +00:00
|
|
|
function onSucceeded() {
|
2024-07-03 02:10:29 +00:00
|
|
|
if (authenticator.hadPrompt) {
|
|
|
|
|
console.log('login succeeded');
|
|
|
|
|
root.waitingForAuth = false;
|
|
|
|
|
root.unlockSucceeded();
|
|
|
|
|
Qt.quit();
|
|
|
|
|
}
|
2022-05-21 03:41:11 +00:00
|
|
|
}
|
2024-06-26 02:57:42 +00:00
|
|
|
|
|
|
|
|
function onFailed(kind: int): void {
|
|
|
|
|
if (kind != 0) { // if this is coming from the noninteractive authenticators
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-06-23 17:03:12 +00:00
|
|
|
console.log('login failed');
|
2024-06-26 02:57:42 +00:00
|
|
|
graceLockTimer.restart();
|
|
|
|
|
root.pinLabel = root.wrongPinLabel;
|
2024-06-23 17:03:12 +00:00
|
|
|
root.unlockFailed();
|
2022-05-21 03:41:11 +00:00
|
|
|
}
|
2024-06-26 02:57:42 +00:00
|
|
|
|
2023-10-28 18:44:06 +00:00
|
|
|
function onInfoMessageChanged() {
|
|
|
|
|
console.log('info: ' + authenticator.infoMessage);
|
|
|
|
|
root.info += authenticator.infoMessage + " ";
|
2022-05-21 03:41:11 +00:00
|
|
|
}
|
2024-06-26 02:57:42 +00:00
|
|
|
|
2022-05-21 03:41:11 +00:00
|
|
|
// TODO
|
2023-10-28 18:44:06 +00:00
|
|
|
function onErrorMessageChanged() {
|
|
|
|
|
console.log('error: ' + authenticator.errorMessage);
|
2022-05-21 03:41:11 +00:00
|
|
|
}
|
2024-06-26 02:57:42 +00:00
|
|
|
|
2022-05-21 03:41:11 +00:00
|
|
|
// TODO
|
2023-10-28 18:44:06 +00:00
|
|
|
function onPromptChanged() {
|
|
|
|
|
console.log('prompt: ' + authenticator.prompt);
|
2022-05-21 03:41:11 +00:00
|
|
|
}
|
2024-06-26 02:57:42 +00:00
|
|
|
|
2023-10-28 18:44:06 +00:00
|
|
|
function onPromptForSecretChanged() {
|
|
|
|
|
console.log('prompt secret: ' + authenticator.promptForSecret);
|
2022-05-21 03:41:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|