From 132129aaf1377ae2787d9e232cc55686108c0d08 Mon Sep 17 00:00:00 2001 From: Leo Carvalho <38107116+Sveimoldr@users.noreply.github.com> Date: Fri, 20 Oct 2023 11:16:13 -0300 Subject: [PATCH 01/15] Create login.js --- web/assets/js/login.js | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 web/assets/js/login.js diff --git a/web/assets/js/login.js b/web/assets/js/login.js new file mode 100644 index 0000000000..80d1b8d5ce --- /dev/null +++ b/web/assets/js/login.js @@ -0,0 +1,49 @@ + +function readBody(xhr) { + var data; + if (!xhr.responseType || xhr.responseType === "text") { + data = xhr.responseText; + } else if (xhr.responseType === "document") { + data = xhr.responseXML; + } else { + data = xhr.response; + } + return data; +} + + +function doLogin() { + var url = "sapphire-api/lobby/login"; + var params = "{\"username\":\"" + document.getElementsByName('username')[0].value + "\",\"pass\":\"" + document.getElementsByName('password')[0].value + "\"}"; + var xhr = new XMLHttpRequest(); + xhr.open("POST", url, true); + + xhr.onreadystatechange = function() { + if (xhr.readyState == 4) { + try { + var response = readBody(xhr); + var parsed = JSON.parse(response); + window.external.Boot(parsed.sId, parsed.lobbyHost, parsed.frontierHost); + } catch(err) { + document.getElementById("Error").innerHTML = "Login failed."; + } + } + } + + xhr.send(params); +} + + +function keypressing(e) { + if (!e) e = window.event; + var keyCode = e.keyCode || e.which; + if (keyCode == '13'){ + doLogin(); + return false; + } +} + +document.getElementsByName('password')[0].addEventListener('keypress', function(event) { + return keypressing(event); +}); +document.getElementById('submitButton').addEventListener('click', doLogin); From 364c304d4a789dc3ab115078487d789aeeb670a8 Mon Sep 17 00:00:00 2001 From: Leo Carvalho <38107116+Sveimoldr@users.noreply.github.com> Date: Fri, 20 Oct 2023 11:17:57 -0300 Subject: [PATCH 02/15] Update login.html --- web/login.html | 176 ++++++++++++++++--------------------------------- 1 file changed, 55 insertions(+), 121 deletions(-) diff --git a/web/login.html b/web/login.html index 172a23f314..ba4c12edf0 100644 --- a/web/login.html +++ b/web/login.html @@ -1,129 +1,63 @@ -
- - -