summaryrefslogtreecommitdiff
path: root/modules/lock/Pam.qml
blob: 44e8671023d0648d58641bfe811c0f62fccf6b43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import Quickshell.Wayland
import Quickshell.Services.Pam
import QtQuick

PamContext {
    id: root

    required property WlSessionLock lock

    property string state: "none"
    property string buffer: ""

    function handleKey(event: KeyEvent): void {
        if (active)
            return;

        if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
            start();
        } else if (event.key === Qt.Key_Backspace) {
            if (event.modifiers & Qt.ControlModifier) {
                buffer = "";
            } else {
                buffer = buffer.slice(0, -1);
            }
        } else if (" abcdefghijklmnopqrstuvwxyz1234567890`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?".includes(event.text.toLowerCase())) {
            // No illegal characters (you are insane if you use unicode in your password)
            buffer += event.text;
        }
    }

    onResponseRequiredChanged: {
        if (!responseRequired)
            return;

        respond(buffer);
        buffer = "";
    }

    onCompleted: res => {
        if (res === PamResult.Success)
            return lock.unlock();

        if (res === PamResult.Error)
            state = "error";
        else if (res === PamResult.MaxTries)
            state = "max";
        else if (res === PamResult.Failed)
            state = "fail";
    }
}