add login page

This commit is contained in:
Arthur Lu 2022-12-12 14:57:43 -08:00
parent 80a442f3c0
commit 1473626373
4 changed files with 72 additions and 4 deletions

View File

@ -5,10 +5,7 @@ window.addEventListener("DOMContentLoaded", init);
async function init () { async function init () {
let cookie = document.cookie; let cookie = document.cookie;
if (cookie === '') { if (cookie === '') {
let username = prompt("username: "); window.location.href = "login.html";
let password = prompt("password: ")
let ticket = await requestTicket(username, password);
setTicket(ticket.data.ticket);
} }
let nodes = await request("/nodes", "GET", null); let nodes = await request("/nodes", "GET", null);

25
login.css Normal file
View File

@ -0,0 +1,25 @@
.center-div {
display: flex;
justify-content: center;
}
fieldset {
border: solid white 1px;
border-radius: 5px;
width: fit-content;
}
input, label, legend {
font-family: monospace;
color: white;
font-size: 14px;
background-color: black;
}
input {
border: solid white 1px;
}
button {
margin-top: 10px;
}

25
login.html Normal file
View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>tronnet - client</title>
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="stylesheet" href="login.css" type="text/css">
<script src="login.js" type="module"></script>
</head>
<body>
<div class="center-div">
<form>
<fieldset>
<legend>Proxmox VE Login</legend>
<label for="username">Username: </label><input type="text" id="username" name="username"><br>
<label for="username">Password: </label><input type="password" id="password" name="password"><br>
<div class="btn-group">
<button id="submit">LOGIN</button>
</div>
</fieldset>
</form>
</div>
</body>
</html>

21
login.js Normal file
View File

@ -0,0 +1,21 @@
import {requestTicket, setTicket} from "./utils.js";
window.addEventListener("DOMContentLoaded", init);
function init (){
let formSubmitButton = document.querySelector("#submit");
formSubmitButton.addEventListener("click", loginFormSubmitHandler);
}
async function loginFormSubmitHandler () {
let form = document.querySelector("form");
let formData = new FormData(form);
try {
let ticket = await requestTicket(formData.username, formData.password);
await setTicket(ticket);
window.location.href = "index.html";
}
catch (error) {
console.log(error);
}
}