From 2e38ecd15bb7860bd10863fac0da54c6cb6ce57a Mon Sep 17 00:00:00 2001 From: Jakub Nowak Date: Sun, 9 Feb 2025 20:43:04 +0800 Subject: [PATCH] Basic authentication flow --- index.html | 3 ++- js/authenticate.js | 25 +++++++++++++++++++++++++ js/class/util.js | 6 +++++- js/index.js | 2 +- 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 js/authenticate.js diff --git a/index.html b/index.html index 181158d..b7df774 100644 --- a/index.html +++ b/index.html @@ -58,7 +58,7 @@
- +
@@ -75,6 +75,7 @@ + diff --git a/js/authenticate.js b/js/authenticate.js new file mode 100644 index 0000000..bc2adfb --- /dev/null +++ b/js/authenticate.js @@ -0,0 +1,25 @@ +function authenticate(){ + const selectedUser = users[currentUser].id; + + lightdm.cancel_authentication(); + lightdm.authenticate(selectedUser); +} + +async function authenticationComplete() { + const selectedSession = sessions[currentSession].id; + + await lightdm.respond($("#password-input").value); + lightdm.start_session(selectedSession); +} + +function bindAuthenticate() { + $("#password-input").onkeypress = function(e) { + var keycode = e.code || e.key; + if(keycode == "Enter"){ + authenticate(); + return; + } + } + + window.lightdm.authentication_complete.connect(authenticationComplete); +} diff --git a/js/class/util.js b/js/class/util.js index 4e7e1cb..4accb1b 100644 --- a/js/class/util.js +++ b/js/class/util.js @@ -1 +1,5 @@ -function $(c) { return document.querySelector(c); } \ No newline at end of file +function $(c) { return document.querySelector(c); } + +function wait(ms) { + return new Promise((resolve) => setTimeout(resolve, ms)); +} diff --git a/js/index.js b/js/index.js index 550fdad..5e2c77b 100644 --- a/js/index.js +++ b/js/index.js @@ -7,7 +7,7 @@ async function initGreeter(){ populateSessions(); populateUsers(); - console.log(lightdm.default_session); + bindAuthenticate(); } window.addEventListener("GreeterReady", () => {