add js stuff

This commit is contained in:
Adora Laura Kalb 2023-08-17 12:15:47 +02:00
parent a9e802f44a
commit 9580e41c59
Signed by: adoralaura
GPG key ID: 7A4552166FC8C056
3 changed files with 78 additions and 3 deletions

View file

@ -59,10 +59,13 @@
<div class="form-group"> <div class="form-group">
<label for="password" class="required">Password</label> <label for="password" class="required">Password</label>
<input type="password" class="form-control" id="password" placeholder="*******" <input type="password" class="form-control" id="password" placeholder="*******"
required="required"> required="required" oninput="HandlePasswordInput();">
<label for="password-repeat" class="required">Repeat Password</label> <label for="password-repeat" class="required">Repeat Password</label>
<input type="password" class="form-control" id="password-repeat" placeholder="*******" <input type="password" class="form-control" id="password-repeat" placeholder="*******"
required="required"> required="required" oninput="HandlePasswordInput();">
</div>
<div id="password-info" class="alert alert-danger" role="alert" style="margin-bottom: 15px; display: none;">
</div> </div>
<!-- Shared Secret --> <!-- Shared Secret -->
@ -72,7 +75,7 @@
required="required"> required="required">
</div> </div>
<!-- Submit button --> <!-- Submit button -->
<input class="btn btn-primary" type="submit" value="Register"> <input id="submit-button" class="btn btn-primary" type="submit" value="Register">
</form> </form>
</div> </div>
</div> </div>
@ -91,6 +94,7 @@
<!-- Halfmoon JS --> <!-- Halfmoon JS -->
<script src="/static/halfmoon.min.js" defer></script> <script src="/static/halfmoon.min.js" defer></script>
<script src="/static/script.js" defer></script> <script src="/static/script.js" defer></script>
<script src="/static/sha1.js" defer></script>
</body> </body>
</html> </html>

View file

@ -0,0 +1,50 @@
async function handleSubmit() {
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 password = document.getElementById("password").value
var sharedsecret = document.getElementById("sharedsecret").value
var admin = "notadmin"
var string = `${nonce.nonce}\0${username}\0${password}\0${admin}`
const hash = new jsSHA("SHA-1", "TEXT", { hmacKey : { value : sharedsecret, format: "TEXT" }})
}
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');
}
}

21
static/sha1.js Normal file

File diff suppressed because one or more lines are too long