forked from chookspace/chookchat
Settings
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
<ul>
|
||||
<li><a id="loginLink" href="/login">login</a></li>
|
||||
<li><a href="/settings">settings</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
</div>
|
||||
|
||||
<ul>
|
||||
<li><a href="/">home</a></li>
|
||||
<li><a id="loginLink" href="/login">login</a></li>
|
||||
<li><a href="/settings">settings</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
<div class="login" id="posts">
|
||||
|
||||
@@ -51,7 +51,7 @@ async function register() {
|
||||
});
|
||||
|
||||
if (result.status < 200 || result.status >= 400) {
|
||||
alert("fard");
|
||||
alert(await result.text());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -96,23 +96,19 @@ document.addEventListener('DOMContentLoaded', async function() {
|
||||
|
||||
if (window.fetch) {
|
||||
// We know the fetch API exists, so hide the stuff that doesn't rely on it
|
||||
|
||||
const form = document.getElementById("postbox-form");
|
||||
if (!form) {
|
||||
return;
|
||||
}
|
||||
form.style.display = 'none';
|
||||
const userStatus = await checkLoginStatus();
|
||||
|
||||
const postbox = document.getElementById("postbox");
|
||||
if (!postbox) {
|
||||
return;
|
||||
}
|
||||
|
||||
const userStatus = await checkLoginStatus();
|
||||
|
||||
// if we're logged in, show the post box,
|
||||
// otherwise show a welcome message, encouraging users to sign up/log in
|
||||
if (userStatus === "") {
|
||||
if (window.location.pathname === "/settings") {
|
||||
window.location.href = "/login";
|
||||
}
|
||||
const newElement = document.createElement("p");
|
||||
newElement.textContent = "Welcome to Chookchat!\nTo get posting, click 'login' to log in or create an account.\nEnjoy your stay!";
|
||||
postbox.appendChild(newElement);
|
||||
@@ -135,7 +131,89 @@ document.addEventListener('DOMContentLoaded', async function() {
|
||||
loginLink.textContent = "hello, " + userStatus + "!";
|
||||
loginLink.href = "/profile/" + userStatus;
|
||||
}
|
||||
|
||||
const form = document.getElementById("postbox-form");
|
||||
if (!form) {
|
||||
return;
|
||||
}
|
||||
form.style.display = 'none';
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
async function settingsChangePassword() {
|
||||
const oldpassword = document.getElementById("change-password-oldpassword");
|
||||
const newpassword = document.getElementById("change-password");
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('oldpassword', oldpassword.value);
|
||||
formData.append('newpassword', newpassword.value);
|
||||
|
||||
const result = await fetch('/settings/changePassword', {
|
||||
method: "POST",
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (result.status < 200 || result.status >= 400) {
|
||||
alert("for whatever reason your password wasn't changed");
|
||||
} else {
|
||||
alert("your password was changed!");
|
||||
}
|
||||
}
|
||||
|
||||
async function settingsChangeUsername() {
|
||||
const password = document.getElementById("change-username-password");
|
||||
const newusername = document.getElementById("change-username");
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('password', password.value);
|
||||
formData.append('newusername', newusername.value);
|
||||
|
||||
const result = await fetch('/settings/changeUsername', {
|
||||
method: "POST",
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (result.status < 200 || result.status >= 400) {
|
||||
alert("for whatever reason your username wasn't changed");
|
||||
} else {
|
||||
alert("your username was changed!");
|
||||
}
|
||||
}
|
||||
|
||||
async function settingsChangeBio() {
|
||||
const bio = document.getElementById("change-bio");
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('bio', bio.value);
|
||||
|
||||
const result = await fetch('/settings/changeBio', {
|
||||
method: "POST",
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (result.status < 200 || result.status >= 400) {
|
||||
alert("for whatever reason your bio wasn't changed");
|
||||
} else {
|
||||
alert("your bio was changed!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function invalidateAllSessions() {
|
||||
const formData = new FormData();
|
||||
formData.append('a', 'a');
|
||||
|
||||
const result = await fetch('/settings/invalidateAllSessions', {
|
||||
method: "POST",
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (result.status < 200 || result.status >= 400) {
|
||||
alert("for whatever reason your sessions weren't invalidated");
|
||||
} else {
|
||||
alert("your sessions were invalidated!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
61
client/settings.html
Normal file
61
client/settings.html
Normal file
@@ -0,0 +1,61 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>posts</title>
|
||||
<link rel="stylesheet" type="text/css" href="/style.css">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<script src="/script.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<nav>
|
||||
<div id="brand">
|
||||
<h2><a href="/">chookchat</a></h2>
|
||||
</div>
|
||||
|
||||
<ul>
|
||||
<li><a id="loginLink" href="/login">login</a></li>
|
||||
<li><a href="/settings">settings</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
<div id="posts">
|
||||
<div id="posts-header">
|
||||
<h1>settings</h1>
|
||||
</div>
|
||||
<div id="password-settings">
|
||||
<h3>password</h3>
|
||||
<p>Enter a new password in the box, and click 'change password' to set a new password</p>
|
||||
<label for="change-password-oldpassword">Old password:</label>
|
||||
<input id="change-password-oldpassword" type="password"></input>
|
||||
<br>
|
||||
<label for="change-password">New password:</label>
|
||||
<input id="change-password" type="password"></input>
|
||||
<br>
|
||||
<button onclick="settingsChangePassword()">Change Password</button>
|
||||
</div>
|
||||
<div id="invalidate-sessions">
|
||||
<h3>invalidate sessions</h3>
|
||||
<p>this button will invalidate all your sessions, and you will have to log in again on all your devices.</p>
|
||||
<button onclick="invalidateAllSessions()">Invalidate All Sessions</button>
|
||||
</div>
|
||||
<div id="username-settings">
|
||||
<h3>username</h3>
|
||||
<p>Enter a new username in the box, and click 'set username' to set a new username</p>
|
||||
<p>Note: any links to your profile will break! However, any links to your posts will remain.</p>
|
||||
<label for="change-username">New username:</label>
|
||||
<input id="change-username"></input>
|
||||
<br>
|
||||
<label for="change-username-password">Password:</label>
|
||||
<input id="change-username-password" type="password"></input>
|
||||
<br>
|
||||
<button onclick="settingsChangeUsername()">Change Username</button>
|
||||
</div>
|
||||
<div id="bio-settings">
|
||||
<h3>bio</h3>
|
||||
<p>set a new bio here!</p>
|
||||
<textarea id="change-bio"></textarea>
|
||||
<br>
|
||||
<button onclick="settingsChangeBio()">Change Bio</button>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user