mirror of
https://github.com/iancoleman/shamir.git
synced 2025-11-18 00:50:59 +00:00
feat: Move the error message to the top of the page, update the error messages
This commit is contained in:
parent
eee000a312
commit
73fb513b42
3 changed files with 44 additions and 38 deletions
|
|
@ -884,6 +884,7 @@ textarea.form-control {
|
|||
<p class="mb-0">Split your secret into parts which can be combined back into the original secret using some or all of the parts.</p>
|
||||
</div>
|
||||
</div>
|
||||
<p id="error-message" class="text-red-700 my-3 w-full p-3 bg-red-100 rounded-lg hidden border-red-200 border"></p>
|
||||
<div class="w-full flex gap-2 border-b border-zinc-200 border-solid border-0">
|
||||
<div id="split-secret-tab" role="tab" class="px-2 leading-8 mb-1 text-sm font-semibold cursor-pointer hover:bg-zinc-100 rounded-lg relative active-tab">Split Secret</div>
|
||||
<div id="combine-secret-tab" role="tab" class="px-2 leading-8 mb-1 text-sm cursor-pointer hover:bg-zinc-100 rounded-lg relative">Combine Secret</div>
|
||||
|
|
@ -903,7 +904,6 @@ textarea.form-control {
|
|||
<p class="mb-1">Distribute one file to each person in your group.</p>
|
||||
<p class="mb-1">If <span id="recreatesize">3</span> of those people can combine the contents of their file using this page, they can view the secret.</p>
|
||||
<p class="mb-3">Remember to delete the parts from your computer once you're finished. If you use a rubbish bin for deleted files, also remove them from the rubbish bin.</p>
|
||||
<p id="error-message" class="text-red-700 my-3 w-full p-3 bg-red-100 rounded-lg hidden border-red-200 border"></p>
|
||||
<h2 class="text-3xl my-3">Parts</h2>
|
||||
<ol id="generated" class="max-w-full break-words rounded-lg overflow-hidden">
|
||||
<li>Enter your secret above.</li>
|
||||
|
|
@ -1937,9 +1937,11 @@ textarea.form-control {
|
|||
DOM.parts.addEventListener("input", combineParts);
|
||||
|
||||
DOM.splitSecretTab.addEventListener("click", () => {
|
||||
clearError()
|
||||
switchTab(true)
|
||||
})
|
||||
DOM.combineSecretTab.addEventListener("click", () => {
|
||||
clearError()
|
||||
switchTab(false)
|
||||
})
|
||||
}
|
||||
|
|
@ -1954,6 +1956,16 @@ textarea.form-control {
|
|||
DOM.combineSecret.classList.toggle("hidden", split)
|
||||
}
|
||||
|
||||
function setError(message) {
|
||||
DOM.error.textContent = "Error: " + message;
|
||||
DOM.error.classList.toggle("hidden", false)
|
||||
}
|
||||
|
||||
function clearError() {
|
||||
DOM.error.textContent = "";
|
||||
DOM.error.classList.toggle("hidden", true)
|
||||
}
|
||||
|
||||
function generateParts() {
|
||||
// Clear old generated
|
||||
DOM.generated.innerHTML = "";
|
||||
|
|
@ -1964,48 +1976,39 @@ textarea.form-control {
|
|||
var required = parseFloat(DOM.required.value);
|
||||
// validate the input
|
||||
if (total < 2) {
|
||||
DOM.error.textContent = "Total must be at least 1";
|
||||
DOM.error.classList.toggle("hidden", false)
|
||||
setError("Total must be at least 2")
|
||||
return;
|
||||
}
|
||||
else if (total > 255) {
|
||||
DOM.error.textContent = "Total must be at most 255";
|
||||
DOM.error.classList.toggle("hidden", false)
|
||||
setError("Total must be at most 255")
|
||||
return;
|
||||
}
|
||||
else if (required < 2) {
|
||||
DOM.error.textContent = "Required must be at least 1";
|
||||
DOM.error.classList.toggle("hidden", false)
|
||||
setError("Required must be at least 2")
|
||||
return;
|
||||
}
|
||||
else if (required > 255) {
|
||||
DOM.error.textContent = "Required must be at most 255";
|
||||
DOM.error.classList.toggle("hidden", false)
|
||||
setError("Required must be at most 255")
|
||||
return;
|
||||
}
|
||||
else if (isNaN(total)) {
|
||||
DOM.error.textContent = "Invalid value for total";
|
||||
DOM.error.classList.toggle("hidden", false)
|
||||
setError("Invalid value for total")
|
||||
return;
|
||||
}
|
||||
else if (isNaN(required)) {
|
||||
DOM.error.textContent = "Invalid value for required";
|
||||
DOM.error.classList.toggle("hidden", false)
|
||||
setError("Invalid value for required")
|
||||
return;
|
||||
}
|
||||
else if (required > total) {
|
||||
DOM.error.textContent = "Required must be less than total";
|
||||
DOM.error.classList.toggle("hidden", false)
|
||||
setError("Required must be less than total")
|
||||
return;
|
||||
}
|
||||
else if (secret.length == 0) {
|
||||
DOM.error.textContent = "Secret is blank";
|
||||
DOM.error.classList.toggle("hidden", false)
|
||||
setError("Secret is blank")
|
||||
return;
|
||||
}
|
||||
else {
|
||||
DOM.error.classList.toggle("hidden", true)
|
||||
DOM.error.textContent = "";
|
||||
clearError()
|
||||
}
|
||||
// Generate the parts to share
|
||||
var minPad = 1024; // see https://github.com/amper5and/secrets.js#note-on-security
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
<p class="mb-0">Split your secret into parts which can be combined back into the original secret using some or all of the parts.</p>
|
||||
</div>
|
||||
</div>
|
||||
<p id="error-message" class="text-red-700 my-3 w-full p-3 bg-red-100 rounded-lg hidden border-red-200 border"></p>
|
||||
<div class="w-full flex gap-2 border-b border-zinc-200 border-solid border-0">
|
||||
<div id="split-secret-tab" role="tab" class="px-2 leading-8 mb-1 text-sm font-semibold cursor-pointer hover:bg-zinc-100 rounded-lg relative active-tab">Split Secret</div>
|
||||
<div id="combine-secret-tab" role="tab" class="px-2 leading-8 mb-1 text-sm cursor-pointer hover:bg-zinc-100 rounded-lg relative">Combine Secret</div>
|
||||
|
|
@ -35,7 +36,6 @@
|
|||
<p class="mb-1">Distribute one file to each person in your group.</p>
|
||||
<p class="mb-1">If <span id="recreatesize">3</span> of those people can combine the contents of their file using this page, they can view the secret.</p>
|
||||
<p class="mb-3">Remember to delete the parts from your computer once you're finished. If you use a rubbish bin for deleted files, also remove them from the rubbish bin.</p>
|
||||
<p id="error-message" class="text-red-700 my-3 w-full p-3 bg-red-100 rounded-lg hidden border-red-200 border"></p>
|
||||
<h2 class="text-3xl my-3">Parts</h2>
|
||||
<ol id="generated" class="max-w-full break-words rounded-lg overflow-hidden">
|
||||
<li>Enter your secret above.</li>
|
||||
|
|
|
|||
|
|
@ -24,9 +24,11 @@
|
|||
DOM.parts.addEventListener("input", combineParts);
|
||||
|
||||
DOM.splitSecretTab.addEventListener("click", () => {
|
||||
clearError()
|
||||
switchTab(true)
|
||||
})
|
||||
DOM.combineSecretTab.addEventListener("click", () => {
|
||||
clearError()
|
||||
switchTab(false)
|
||||
})
|
||||
}
|
||||
|
|
@ -41,6 +43,16 @@
|
|||
DOM.combineSecret.classList.toggle("hidden", split)
|
||||
}
|
||||
|
||||
function setError(message) {
|
||||
DOM.error.textContent = "Error: " + message;
|
||||
DOM.error.classList.toggle("hidden", false)
|
||||
}
|
||||
|
||||
function clearError() {
|
||||
DOM.error.textContent = "";
|
||||
DOM.error.classList.toggle("hidden", true)
|
||||
}
|
||||
|
||||
function generateParts() {
|
||||
// Clear old generated
|
||||
DOM.generated.innerHTML = "";
|
||||
|
|
@ -51,48 +63,39 @@
|
|||
var required = parseFloat(DOM.required.value);
|
||||
// validate the input
|
||||
if (total < 2) {
|
||||
DOM.error.textContent = "Total must be at least 1";
|
||||
DOM.error.classList.toggle("hidden", false)
|
||||
setError("Total must be at least 2")
|
||||
return;
|
||||
}
|
||||
else if (total > 255) {
|
||||
DOM.error.textContent = "Total must be at most 255";
|
||||
DOM.error.classList.toggle("hidden", false)
|
||||
setError("Total must be at most 255")
|
||||
return;
|
||||
}
|
||||
else if (required < 2) {
|
||||
DOM.error.textContent = "Required must be at least 1";
|
||||
DOM.error.classList.toggle("hidden", false)
|
||||
setError("Required must be at least 2")
|
||||
return;
|
||||
}
|
||||
else if (required > 255) {
|
||||
DOM.error.textContent = "Required must be at most 255";
|
||||
DOM.error.classList.toggle("hidden", false)
|
||||
setError("Required must be at most 255")
|
||||
return;
|
||||
}
|
||||
else if (isNaN(total)) {
|
||||
DOM.error.textContent = "Invalid value for total";
|
||||
DOM.error.classList.toggle("hidden", false)
|
||||
setError("Invalid value for total")
|
||||
return;
|
||||
}
|
||||
else if (isNaN(required)) {
|
||||
DOM.error.textContent = "Invalid value for required";
|
||||
DOM.error.classList.toggle("hidden", false)
|
||||
setError("Invalid value for required")
|
||||
return;
|
||||
}
|
||||
else if (required > total) {
|
||||
DOM.error.textContent = "Required must be less than total";
|
||||
DOM.error.classList.toggle("hidden", false)
|
||||
setError("Required must be less than total")
|
||||
return;
|
||||
}
|
||||
else if (secret.length == 0) {
|
||||
DOM.error.textContent = "Secret is blank";
|
||||
DOM.error.classList.toggle("hidden", false)
|
||||
setError("Secret is blank")
|
||||
return;
|
||||
}
|
||||
else {
|
||||
DOM.error.classList.toggle("hidden", true)
|
||||
DOM.error.textContent = "";
|
||||
clearError()
|
||||
}
|
||||
// Generate the parts to share
|
||||
var minPad = 1024; // see https://github.com/amper5and/secrets.js#note-on-security
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue