login prototype

This commit is contained in:
Arthur Lu 2022-12-10 18:02:29 -08:00
commit 82879d2cf1
3 changed files with 125 additions and 0 deletions

12
index.html Normal file
View File

@ -0,0 +1,12 @@
<!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">
<script src="index.js" type="module"></script>
</head>
<body>
</body>
</html>

53
index.js Normal file
View File

@ -0,0 +1,53 @@
window.addEventListener("DOMContentLoaded", init);
async function init () {
let cookie = document.cookie;
if(cookie === '') {
let username = prompt("username: ");
let password = prompt("password: ")
let ticket = await requestTicket(username, password);
setTicket(ticket.data.ticket);
}
let nodes = await request("/nodes", "GET", null);
console.log(nodes);
}
async function requestTicket (username, password) {
let prms = new URLSearchParams({username: `${username}@pve`, password: password});
let response = await fetch("https://pve.tronnet.net/api2/json/access/ticket", {
method: "POST",
mode: "cors",
credentials: "include",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: prms.toString()
});
let data = await response.json();
return data;
}
async function request (path, method, body) {
let prms = new URLSearchParams(body);
let response = await fetch(`https://pve.tronnet.net/api2/json${path}`, {
method: method,
mode: "cors",
credentials: "include",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Cookie": document.cookie
}
});
if(method == "POST") {
response.body = prms.toString();
}
let data = await response.json();
return data;
}
function setTicket (ticket) {
let d = new Date();
d.setTime(d.getTime() + (2*60*60*1000));
document.cookie = `PVEAuthCookie=${ticket}; path=/; expires=${d.toUTCString()};`;
}

60
style.css Normal file
View File

@ -0,0 +1,60 @@
body {
background-color:black;
}
.std-text {
font-family: monospace;
color: white;
margin: 20px 0px 20px 0px;
}
h1 {
font-size: 72px;
text-align: center;
}
h2 {
font-size: 32px;
text-align: center;
}
h3 {
font-size: 24px;
text-align: center;
}
p {
font-size: 14px;
text-align: left;
}
.center-div {
width: 50%;
margin-left: auto;
margin-right: auto;
}
.btn-group {
margin: 0 auto;
display: flex;
justify-content: center;
}
.btn-group button {
background-color: #00ff00; /* Green background */
color: black; /* White text */
padding: 10px; /* Some padding */
margin: 0px 5px 0px 5px;
cursor: pointer; /* Pointer/hand icon */
border: none;
}
.btn-group:after {
content: "";
clear: both;
display: table;
}
.btn-group button:hover {
background-color: #008800;
}