summaryrefslogtreecommitdiff
path: root/src/main.js
diff options
context:
space:
mode:
authorcurly <curly@infernal.garden>2024-07-15 17:08:30 -0600
committercurly <curly@infernal.garden>2024-07-15 17:08:30 -0600
commit30b53f64f3bba30d259f04dcb6669a56203f94c6 (patch)
tree2c6e67a12844ebb9daf63077e73b25f9c58eeaa8 /src/main.js
parente6150a01fef7cb8614f1337abbc9630be373aac5 (diff)
downloadpoko_web-30b53f64f3bba30d259f04dcb6669a56203f94c6.tar.gz
poko_web-30b53f64f3bba30d259f04dcb6669a56203f94c6.tar.bz2
poko_web-30b53f64f3bba30d259f04dcb6669a56203f94c6.zip
styled
Diffstat (limited to 'src/main.js')
-rw-r--r--src/main.js85
1 files changed, 50 insertions, 35 deletions
diff --git a/src/main.js b/src/main.js
index 2b880a2..3060767 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,4 +1,3 @@
-// const host = window.location.protocol + "//" + window.location.host;
const server = window.location.protocol + "//" + window.location.hostname + ":8000";
const host = window.location.protocol + "//" + window.location.host;
const client_id = "POKO Web 0.0"
@@ -64,7 +63,7 @@ async function register() {
if (req.status == 201) {
await login(req.body.id, password)
- window.location.href = host
+ window.location.href = host + "/user.html"
} else {
alert(req.status + ": " + req.body)
}
@@ -89,7 +88,7 @@ async function login(id, password) {
if (req.status == 200) {
// Set session cookie
set_session(req.body, id)
- window.location.href = host;
+ window.location.href = host + "/user.html";
} else {
alert(req.status + ": " + req.body)
}
@@ -142,56 +141,64 @@ async function logout() {
}
}
-async function has_session() {
+async function is_logged_in() {
const session = get_session();
const id = get_id();
- const users = await userlist();
- const content = document.getElementById("content");
-
- // If session exists
if (session != "") {
- // If ID exists
if (id != "") {
const url = server + "/user/get"
const body = {"id": id, "session": session}
const req = await xhttp_post(url, body);
if (req.status == 200) {
-
- const tokens = format_tokovec(req.body.tokovec);
-
- content.innerHTML = `
- <div id="userinfo">
- <h3>User Info</h3>
- <p>Username: ${req.body.name}</p>
- <p>ID: ${id}</p>
- </div>
- <div id="balance">
- <h3>Tokens Balance</h3>
- ${tokens}
- </div>
- <div id="actions">
- <h3>Actions</h3>
- <a href="/transfer.html"><button>Transfer</button></a>
- <button onclick="logout()">Logout</button>
- <button onclick="logout_all()">Logout All //TODO</button>
- </div>
- <div id="users">
- <h3>Users</h3>
- ${users}
- </div>
- `;
+ return true
} else if (req.status == 404) {
if (req.body == "Not Authenticated") {
del_session()
+ return false
}
}
} else {
del_session()
}
- } else {
- content.innerHTML += users;
+ }
+
+ return false
+}
+
+async function user() {
+ const session = get_session();
+ const id = get_id();
+
+ const user_name = document.getElementById("user.name");
+ const user_id = document.getElementById("user.id");
+ const users = document.getElementById("users");
+ const balance = document.getElementById("balance");
+
+
+ if (is_logged_in()) {
+
+
+ const url = server + "/user/get"
+ const body = {"id": id, "session": session}
+ const req = await xhttp_post(url, body);
+
+ if (req.status == 200) {
+
+ const tokens = format_tokovec(req.body.tokovec);
+ const user_list = await userlist();
+
+ user_name.innerHTML = `Name: ${req.body.name}`;
+ user_id.innerHTML = `ID: ${id}`;
+ users.innerHTML += user_list;
+ balance.innerHTML += tokens;
+
+ } else if (req.status == 404) {
+ if (req.body == "Not Authenticated") {
+ del_session()
+ }
+ }
}
}
@@ -226,4 +233,12 @@ async function userlist() {
} catch {}
return out
+}
+
+function transfer() {}
+
+function transfer_form() {
+ const to_id = document.getElementById("to_id").value;
+ const color = document.getElementById("color").value;
+ const amount = document.getElementById("amount").value;
} \ No newline at end of file