synapse-registration/static/script.js
2023-08-18 23:43:50 +02:00

72 lines
No EOL
2.2 KiB
JavaScript

async function submitForm() {
var nonce_request = await fetch("https://matrix-reg.test.lauka.dev/_synapse/admin/v1/register", {
method: 'GET',
redirect: 'follow',
mode: "cors"
})
var nonce = await nonce_request.json()
var username = document.getElementById("username").value
var displayname = document.getElementById("displayname").value
var password = document.getElementById("password").value
var sharedsecret = document.getElementById("sharedsecret").value
var admin = "notadmin"
var string = `${nonce.nonce}\0${username}\0${password}\0${admin}`
console.log("String: ", string)
const hasher = new jsSHA("SHA-1", "TEXT", { hmacKey : { value : sharedsecret, format: "TEXT" }})
hasher.update(string)
var hmac = hasher.getHash('HEX')
console.log("HMAC: ", hmac)
var register_body = JSON.stringify({
"nonce": nonce.nonce,
"username": displayname,
"password": password,
"admin": false,
"mac": hmac
})
var register_request = await fetch("https://matrix-reg.test.lauka.dev/_synapse/admin/v1/register", {
method: 'POST',
mode: "cors",
body: register_body
})
console.log(await register_request.statusText)
}
function HandlePasswordInput() {
var info = document.getElementById("password-info")
var button = document.getElementById("submit-button")
var messages = []
var password = document.getElementById("password").value
var passwordrepeat = document.getElementById("password-repeat").value
if (password.length < 20) {
messages.push("Password must be 20 letters or more.")
}
if (!(password === passwordrepeat)) {
messages.push("Passwords must match.")
}
if (messages.length == 0) {
info.style.display = 'none'
button.removeAttribute('disabled')
} else if (messages.length == 1) {
info.style.display = 'block'
info.innerHTML = messages[0]
button.setAttribute('disabled','disabled');
} else {
info.style.display = 'block'
string = messages.join(" <br/> ")
info.innerHTML = string
button.setAttribute('disabled','disabled');
}
}