Skip to content

Commit

Permalink
Import codes manually #204
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Apr 21, 2022
1 parent 2d4fa95 commit 8c22d55
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
74 changes: 74 additions & 0 deletions app/import/src/js/manual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// @ts-nocheck
module.exports = {
manualEntry: async () => {
const manual_issuer = document.querySelector("#manual_issuer")
const manual_secret = document.querySelector("#manual_secret")
const manual_description = document.querySelector("#manual_description")

if (manual_issuer.value === "") {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.close],
type: "error",
noLink: true,
defaultId: 0,
cancelId: 0,
message: lang.import_dialog.issuer_required,
})

return logger.warn("Issuer field empty")
}

if (manual_secret.value === "") {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.close],
type: "error",
noLink: true,
defaultId: 0,
cancelId: 0,
message: lang.import_dialog.secret_required,
})

return logger.warn("Secret field empty")
}

const string = `\nName: ${manual_description.value} \nSecret: ${manual_secret.value} \nIssuer: ${manual_issuer.value} \nType: OTP_TOTP\n`

const result = await dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.yes, lang.button.no],
type: "info",
noLink: true,
defaultId: 1,
cancelId: 1,
message: `${lang.import_dialog.correct_qrcode_found_0} ${lang.import_dialog.correct_qrcode_found_1}`,
})

const save_exists = fs.existsSync(path.join(folder_path, "codes", "codes.authme"))

if (result.response === 0) {
if (save_exists === true) {
ipc.invoke("importExistingCodes", Buffer.from(string).toString("base64"))
} else {
ipc.invoke("importCodes", Buffer.from(string).toString("base64"))
}

saveFile(string)
} else {
if (save_exists === true) {
ipc.invoke("importExistingCodes", Buffer.from(string).toString("base64"))
} else {
ipc.invoke("importCodes", Buffer.from(string).toString("base64"))
}
}

const /** @type{LibDialogElement} */ dialog0 = document.querySelector(".dialog0")

dialog0.close()

manual_issuer.value = ""
manual_secret.value = ""
manual_description.value = ""
},
}
2 changes: 2 additions & 0 deletions languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ module.exports = {
"wrong_qrcode_found_1": "\n\nMake sure this is a correct QR code and try again!",
"capture_error": "Error starting capture!",
"no_qrcode_captured": "Not found any QR code on your screen! Make sure the QR code is visible or try to screenshot the QR code and import it as an image!",
"issuer_required": "The name field is required. \n\nPlease try again!",
"secret_required": "The secret field is required. \n\nPlease try again!",
},

"export": [
Expand Down
2 changes: 2 additions & 0 deletions languages/hu.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ module.exports = {
"wrong_qrcode_found_1": "\n\nGyőződj meg róla hogy ez egy jó QR-kód!",
"capture_error": "Nem sikerült a képernyő rögzítése!",
"no_qrcode_captured": "Nem sikerült QR-kódot találni a képernyődön! Győződj meg róla hogy a QR-kód látható vagy próbálj meg egy képernyőképet készíteni a QR-kódról és importáld be képként!",
"issuer_required": "A név megadása kötelező. \n\nPróbálkozz újra!",
"secret_required": "A kulcs megadása kötelező!. \n\nPróbálkozz újra!",
},

"export": [
Expand Down

0 comments on commit 8c22d55

Please sign in to comment.