commit bceae9d4d50c2a0fae0d55c0a44acf9cd49ab889 Author: Arthur Lu Date: Sat Dec 10 18:02:29 2022 -0800 login prototype diff --git a/index.html b/index.html new file mode 100644 index 0000000..794977b --- /dev/null +++ b/index.html @@ -0,0 +1,12 @@ + + + + + + tronnet - client + + + + + + \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..2a5fc86 --- /dev/null +++ b/index.js @@ -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()};`; +} \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..2431052 --- /dev/null +++ b/style.css @@ -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; +} \ No newline at end of file