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: Iris Lightshard
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() {
const adminUsrInput = document.getElementById("input_admin_usr");
const adminUsrInput = document.getElementById("name_entry");
const adminPassInput = document.getElementById("input_admin_pass");
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) {
const headers = new Headers();
headers.set('Authorization', 'Basic ' + btoa(user + ":" + pass));

View file

@ -5,24 +5,22 @@
<title>Felt</title>
<meta name="viewport" content="width=device-width" />
<link href="./style.css" rel="stylesheet" />
</head>
<body>
<div id="errWrapper" style='display:none'><button id="closeErr" onclick="closeErr()">x</button><div id="errDiv"></div></div>
<nav>
<input id="name_entry">
<button id="goto_table">Join Table</button>
<button id="admin_login">Admin Login</button>
<input id="name_entry" onblur="saveName()">
<button id="goto_table" onclick="showAdminModal(false);showTableModal(true)">Join Table</button>
<button id="admin_login" onclick="showTableModal(false);showAdminModal(true)">Admin Login</button>
</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 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 id="admin_modal" onsubmit="return false">
<label>usr<input id="input_admin_usr"></label>
<form id="admin_modal" onsubmit="return false" style="display:none;">
<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>
<div id="dice_log"></div>
<select id="num_dice">

View file

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

View file

@ -15,3 +15,22 @@ function closeErr() {
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();