Skip to content

Commit

Permalink
Option to delete all codes on edit page
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Nov 11, 2021
1 parent e0298a4 commit 92746aa
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
10 changes: 9 additions & 1 deletion app/edit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ <h3>Now you can modify existing codes or add more.</h3>
</svg>
Save modification(s)
</button>

<button class="buttoni" onclick="addMore()">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 13h6m-3-3v6m5 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
Expand All @@ -82,13 +83,20 @@ <h3>Now you can modify existing codes or add more.</h3>
<div class="mx-auto pb-3">
<details class="mb-5 transform ease-in duration-200">
<summary class="font-bold mb-3 cursor-pointer">More options</summary>
<div class="lg:space-x-3 space-y-3 pb-5">
<div class="flex flex-row justify-center gap-3 flex-wrap">
<button class="buttoni" onclick="revertChanges()">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
</svg>
Revert changes
</button>

<button class="buttoni" onclick="deleteCodes()">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
</svg>
Delete codes
</button>
</div>
</details>
</div>
Expand Down
45 changes: 39 additions & 6 deletions app/edit/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const rollback = () => {
if (err) {
logger.error("Failed to create codes.authme folder", err)
} else {
logger.log("codes.authme file created")
logger.log("rollback successful, codes.authme file created")
}
})
} else {
Expand Down Expand Up @@ -397,12 +397,17 @@ const addMore = () => {

counter = 0

const /** @type{LibImportFile} */ imported = convert.fromText(input.toString(), 0)
if (extension === "authme") {
const codes = Buffer.from(JSON.parse(input.toString()).codes, "base64").toString()

for (let i = 0; i < imported.names.length; i++) {
names.push(imported.names[i])
secrets.push(imported.secrets[i])
issuers.push(imported.issuers[i])
const /** @type{LibImportFile} */ imported = convert.fromText(codes.toString(), 0)
const /** @type{LibImportFile} */ imported = convert.fromText(input.toString(), 0)

for (let i = 0; i < imported.names.length; i++) {
names.push(imported.names[i])
secrets.push(imported.secrets[i])
issuers.push(imported.issuers[i])
}
}

go()
Expand Down Expand Up @@ -566,3 +571,31 @@ const revertChanges = () => {
}
})
}

/**
* Delete all codes
*/
const deleteCodes = () => {
dialog
.showMessageBox({
title: "Authme",
buttons: ["Yes", "Cancel"],
defaultId: 1,
cancelId: 1,
type: "warning",
noLink: true,
message: "Are you sure you want to delete all codes? \n\nYou can revert this with a rollback.",
})
.then((result) => {
if (result.response === 0) {
// clear codes
fs.rm(path.join(file_path, "codes", "codes.authme"), (err) => {
if (err) {
return logger.error(`Error deleting codes - ${err}`)
} else {
logger.log("Codes deleted")
}
})

fs.rm(path.join(file_path, "hash.authme"), (err) => {
if (err) {
Loading

0 comments on commit 92746aa

Please sign in to comment.