UI stuff; save and load username in cookie

This commit is contained in:
Iris Lightshard 2023-02-18 20:37:50 -07:00
parent 849c27b7cf
commit b8994d80a9
Signed by: nilix
GPG key ID: 3B7FBC22144E6398
4 changed files with 42 additions and 11 deletions

View file

@ -55,7 +55,7 @@ async function getTables() {
} }
async function doLogin() { async function doLogin() {
const adminUsrInput = document.getElementById("input_admin_usr"); const adminUsrInput = document.getElementById("name_entry");
const adminPassInput = document.getElementById("input_admin_pass"); const adminPassInput = document.getElementById("input_admin_pass");
if (adminUsrInput && adminPassInput) { if (adminUsrInput && adminPassInput) {
@ -69,6 +69,13 @@ async function doLogin() {
} }
} }
function showAdminModal(show) {
const modal = document.getElementById("admin_modal")
if (modal) {
modal.style.display = show ? "block" : "none";
}
}
async function getAdminToken(user, pass) { async function getAdminToken(user, pass) {
const headers = new Headers(); const headers = new Headers();
headers.set('Authorization', 'Basic ' + btoa(user + ":" + pass)); headers.set('Authorization', 'Basic ' + btoa(user + ":" + pass));

View file

@ -5,24 +5,22 @@
<title>Felt</title> <title>Felt</title>
<meta name="viewport" content="width=device-width" /> <meta name="viewport" content="width=device-width" />
<link href="./style.css" rel="stylesheet" /> <link href="./style.css" rel="stylesheet" />
</head> </head>
<body> <body>
<div id="errWrapper" style='display:none'><button id="closeErr" onclick="closeErr()">x</button><div id="errDiv"></div></div> <div id="errWrapper" style='display:none'><button id="closeErr" onclick="closeErr()">x</button><div id="errDiv"></div></div>
<nav> <nav>
<input id="name_entry"> <input id="name_entry" onblur="saveName()">
<button id="goto_table">Join Table</button> <button id="goto_table" onclick="showAdminModal(false);showTableModal(true)">Join Table</button>
<button id="admin_login">Admin Login</button> <button id="admin_login" onclick="showTableModal(false);showAdminModal(true)">Admin Login</button>
</nav> </nav>
<form id="table_modal" onsubmit="return false"> <form id="table_modal" onsubmit="return false" style="display:none;">
<label>Table Name<input id="input_table_name"></label> <label>Table Name<input id="input_table_name"></label>
<label>Table Passcode<input id="input_table_pass"></label> <label>Table Passcode<input id="input_table_pass"></label>
<button type="submit" id="table_join" onclick="dial()">Join</button> <button type="submit" id="table_join" onclick="dial();showTableModal(false);">Join</button>
</form> </form>
<form id="admin_modal" onsubmit="return false"> <form id="admin_modal" onsubmit="return false" style="display:none;">
<label>usr<input id="input_admin_usr"></label>
<label>pass<input type="password" id="input_admin_pass"></label> <label>pass<input type="password" id="input_admin_pass"></label>
<button type="submit" id="admin_login" onclick="doLogin()">login</button> <button type="submit" id="admin_login" onclick="doLogin();showAdminModal(false)">login</button>
</form> </form>
<div id="dice_log"></div> <div id="dice_log"></div>
<select id="num_dice"> <select id="num_dice">

View file

@ -7,6 +7,13 @@ let table = null;
let conn = null; let conn = null;
function showTableModal(show) {
const modal = document.getElementById("table_modal");
if (modal) {
modal.style.display = show ? "block" : "none";
}
}
function dial() { function dial() {
// get tableKey from UI // get tableKey from UI
const tblNameInput = document.getElementById("input_table_name"); const tblNameInput = document.getElementById("input_table_name");

View file

@ -14,4 +14,23 @@ function closeErr() {
if (errWrapper) { if (errWrapper) {
errWrapper.style.display = "none"; errWrapper.style.display = "none";
} }
} }
function saveName() {
const username = document.getElementById("name_entry");
if (username) {
document.cookie = "username=" + username.value;
}
}
function loadName() {
const username = document.getElementById("name_entry");
if (username) {
const cookies = document.cookie.split(";")
if (cookies[0].trim().startsWith("username=")) {
username.value = cookies[0].trim().split("=")[1];
}
}
}
loadName();