coller/src/server/templates/unprotectedNote.html
Julien Riou ee7b5f0c6e
All checks were successful
/ pre-commit (push) Successful in 1m21s
feat: Pass encryption key in URL fragment
- Remove encryptionKey from URL
- Use POST method to pass both password and encryption key
- Parse URL fragment to extract the encryption key from the web (using
  javascript) and from the CLI

Fixes #36.

Signed-off-by: Julien Riou <julien@riou.xyz>
2025-10-01 12:43:04 +02:00

70 lines
No EOL
2.6 KiB
HTML

{{define "unprotectedNote"}}
<!DOCTYPE html>
<html lang="en" data-bs-theme="light">
{{block "head" .}}{{end}}
<body>
{{block "header" .}}{{end}}
{{if .Err}}
{{block "error" .}}{{end}}
{{else if or (gt (len .Note.PasswordHash) 0) .Note.Encrypted}}
<script>var protected = false;</script>
<div class="container mb-4">
<form id="form" method="post" enctype="multipart/form-data">
{{if gt (len .Note.PasswordHash) 0}}
<script>protected = true;</script>
<div class="container mb-4 w-25">
<div class="row text-center justify-content-center">
<label class="col-form-label" for="password">Password</label>
</div>
</div>
<div class="container mb-4 w-25">
<div class="row text-center justify-content-center">
<input type="password" class="form-control" id="password" name="password">
</div>
</div>
{{end}}
{{if .Note.Encrypted}}
<div id="encryption-container">
<div class="container mb-4 w-25">
<div class="row text-center justify-content-center">
<label class="col-form-label" for="password">Encryption key</label>
</div>
</div>
<div class="container mb-4 w-25">
<div class="row text-center justify-content-center">
<input type="password" pattern="^[a-zA-Z0-9]{16,256}$"
title="Letters and numbers with length from 16 to 256" class="form-control"
id="encryption-key" name="encryption-key">
</div>
</div>
</div>
<script>
var encryptionKey = window.location.hash.substr(1);
if (encryptionKey != "") {
document.getElementById("encryption-container").style.display = "none";
document.getElementById("encryption-key").value = encryptionKey;
if (!protected) {
document.getElementById("form").submit();
}
}
</script>
{{end}}
<div class="container mb-4 w-25">
<div class="row text-center justify-content-center">
<button type="btn-submit" id="btn-submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
</div>
{{else}}
{{block "note" .}}{{end}}
{{end}}
{{block "footer" .}}{{end}}
</body>
</html>
{{end}}