synapse-registration/static/script.js

69 lines
2.1 KiB
JavaScript
Raw Normal View History

2023-08-18 21:11:30 +02:00
async function submitForm() {
2023-08-17 12:15:47 +02:00
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
2023-08-18 21:11:30 +02:00
var displayname = document.getElementById("displayname").value
2023-08-17 12:15:47 +02:00
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}`
2023-08-18 21:11:30 +02:00
const hasher = new jsSHA("SHA-1", "TEXT", { hmacKey : { value : sharedsecret, format: "TEXT" }})
hasher.update(string)
var hmac = hasher.getHash('HEX')
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
})
2023-08-17 12:15:47 +02:00
}
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');
}
}