IPost/views/user.html
2022-06-03 08:42:30 +02:00

73 lines
2.6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Logged In</title>
<link rel="stylesheet" href="/css/style.css">
<link rel="stylesheet" href="/css/global.css">
<script src="/js/httppost.js" charset="utf-8"></script>
</head>
<body onload="setuser()">
<ul class="navbar">
<li><a href="/">Home</a></li>
<li><a href="/user">Profile</a></li>
<li><a href="/posts">Posts</a></li>
</ul>
<header>
<h1>Welcome Back!</h1>
</header>
<main>
<form id="login_form" class="form_class" action="login" method="post">
<div class="info_div">
<h2 id="user">User: USER</h2>
<br>
<span class="bio">Bio: <input type="text" id="bio" disabled placeholder="wow such empty"></span>
<button id="changeBio" onclick="bioChanger()">Change Bio</button>
<br>
<button onclick="location.assign('/changePW')">Want to change your password?</button>
<br>
<button onclick="location.assign('/posts')">Want to chat with some cool fellas?</button>
</div>
</form>
</main>
<script>
async function setuser() {
let user = await (await fetch("/api/getuser")).json();
let username
let bio
username = user["username"];
bio = user["bio"]
if(user["error"])username=user["error"];
if(user["error"])bio=user["error"];
if(!bio)bio="wow such empty"
document.getElementById("user").innerText = `User: ${username}`;
document.getElementById("bio").placeholder = decodeURIComponent(atob(bio));
}
async function bioChanger() {
document.getElementById("bio").disabled = !document.getElementById("bio").disabled
document.getElementById("changeBio").innerText = (document.getElementById("bio").disabled && "Change Bio") || "Submit"
if(document.getElementById("bio").disabled) {
document.querySelector('style').innerHTML = '::placeholder {color: white;} #bio {border: 0px solid black}'
}
else
{
document.querySelector('style').innerHTML = '::placeholder {color: black;} #bio {border: 2px solid gray}'
}
if(document.getElementById("bio").disabled) {
let response = await sendBio(document.getElementById("bio").value)
console.log(response);
}
}
async function sendBio(str) {
return await post("/api/setBio",{"Bio":str})
}
</script>
</body>
</html>