2024-02-26 19:20:46 +00:00
|
|
|
if (localStorage.getItem("DONOTSHARE-secretkey") !== null) {
|
2024-05-11 10:35:19 +01:00
|
|
|
window.location.replace("/app/")
|
2024-02-26 19:20:46 +00:00
|
|
|
document.body.innerHTML = "Redirecting..."
|
|
|
|
throw new Error();
|
|
|
|
}
|
|
|
|
if (localStorage.getItem("DONOTSHARE-password") !== null) {
|
2024-05-11 10:35:19 +01:00
|
|
|
window.location.replace("/app/")
|
2024-02-26 19:20:46 +00:00
|
|
|
document.body.innerHTML = "Redirecting..."
|
|
|
|
throw new Error();
|
|
|
|
}
|
|
|
|
|
2024-03-15 13:09:55 +00:00
|
|
|
let remote = localStorage.getItem("homeserverURL")
|
|
|
|
if (remote == null) {
|
|
|
|
localStorage.setItem("homeserverURL", "https://notes.hectabit.org")
|
|
|
|
remote = "https://notes.hectabit.org"
|
|
|
|
}
|
|
|
|
|
2024-02-26 19:20:46 +00:00
|
|
|
let usernameBox = document.getElementById("usernameBox")
|
|
|
|
let passwordBox = document.getElementById("passwordBox")
|
|
|
|
let statusBox = document.getElementById("statusBox")
|
|
|
|
let signupButton = document.getElementById("signupButton")
|
|
|
|
|
|
|
|
function showElements(yesorno) {
|
|
|
|
if (!yesorno) {
|
|
|
|
usernameBox.classList.add("hidden")
|
|
|
|
passwordBox.classList.add("hidden")
|
|
|
|
signupButton.classList.add("hidden")
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
usernameBox.classList.remove("hidden")
|
|
|
|
passwordBox.classList.remove("hidden")
|
|
|
|
signupButton.classList.remove("hidden")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-15 13:09:55 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
document.getElementById("homeserver").innerText = "Your homeserver is: " + remote + ". "
|
|
|
|
});
|
|
|
|
|
2024-05-11 10:35:19 +01:00
|
|
|
signupButton.addEventListener("click", () => {
|
2024-02-26 19:20:46 +00:00
|
|
|
async function doStuff() {
|
|
|
|
let username = usernameBox.value
|
|
|
|
let password = passwordBox.value
|
|
|
|
|
2024-05-11 10:35:19 +01:00
|
|
|
if (username === "") {
|
2024-02-26 19:20:46 +00:00
|
|
|
statusBox.innerText = "A username is required!"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if ((username).length > 20) {
|
|
|
|
statusBox.innerText = "Username cannot be more than 20 characters!"
|
|
|
|
return
|
|
|
|
}
|
2024-05-11 10:35:19 +01:00
|
|
|
if (password === "") {
|
2024-02-26 19:20:46 +00:00
|
|
|
statusBox.innerText = "A password is required!"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if ((password).length < 8) {
|
|
|
|
statusBox.innerText = "8 or more characters are required!"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
showElements(false)
|
|
|
|
statusBox.innerText = "Creating account, please hold on..."
|
|
|
|
|
|
|
|
async function hashpass(pass) {
|
|
|
|
let key = pass
|
|
|
|
for (let i = 0; i < 128; i++) {
|
|
|
|
key = await hashwasm.sha3(key)
|
|
|
|
}
|
|
|
|
return key
|
2024-05-11 10:35:19 +01:00
|
|
|
}
|
2024-02-26 19:20:46 +00:00
|
|
|
|
|
|
|
|
2024-03-15 13:09:55 +00:00
|
|
|
fetch(remote + "/api/signup", {
|
2024-02-26 19:20:46 +00:00
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
username: username,
|
|
|
|
password: await hashpass(password)
|
|
|
|
}),
|
|
|
|
headers: {
|
2024-02-27 20:04:26 +00:00
|
|
|
"Content-Type": "application/json; charset=UTF-8"
|
2024-02-26 19:20:46 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.then((response) => response)
|
|
|
|
.then((response) => {
|
|
|
|
async function doStuff() {
|
|
|
|
let responseData = await response.json()
|
|
|
|
|
2024-05-11 10:35:19 +01:00
|
|
|
if (response.status === 200) {
|
|
|
|
statusBox.innerText = "Redirecting...."
|
2024-02-26 19:20:46 +00:00
|
|
|
localStorage.setItem("DONOTSHARE-secretkey", responseData["key"])
|
|
|
|
localStorage.setItem("DONOTSHARE-password", await hashwasm.sha512(password))
|
|
|
|
|
2024-05-11 10:35:19 +01:00
|
|
|
window.location.href = "/app/"
|
2024-02-26 19:20:46 +00:00
|
|
|
}
|
2024-05-11 10:35:19 +01:00
|
|
|
else if (response.status === 409) {
|
2024-02-26 19:20:46 +00:00
|
|
|
statusBox.innerText = "Username already taken!"
|
|
|
|
showElements(true)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
statusBox.innerText = "Something went wrong!"
|
|
|
|
showElements(true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
doStuff()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
doStuff()
|
|
|
|
});
|