| 1 |
/* |
| 2 |
* This file is part of the 2FA Manager App for Ubuntu Touch |
| 3 |
* Copyright (C) 2019 Joan CiberSheep |
| 4 |
* |
| 5 |
* This App is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License version 3 as |
| 7 |
* published by the Free Software Foundation. |
| 8 |
* |
| 9 |
* |
| 10 |
* This App is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
import QtQuick 2.9 |
| 21 |
import Lomiri.Components 1.3 |
| 22 |
import Lomiri.Components.Popups 1.3 |
| 23 |
import QtQuick.LocalStorage 2.0 |
| 24 |
import "../js/db.js" as KeysDB |
| 25 |
|
| 26 |
Dialog { |
| 27 |
id: renderUri |
| 28 |
|
| 29 |
property var uriJson |
| 30 |
property string authType: keyPeriod.visible |
| 31 |
? "TOTP" |
| 32 |
: "HTOP" |
| 33 |
title: i18n.tr("Add Authenticator Key") |
| 34 |
text: i18n.tr("%1 authenticator key").arg(authType) |
| 35 |
|
| 36 |
TextField { |
| 37 |
id: userDdescription |
| 38 |
placeholderText: i18n.tr("Add a description") |
| 39 |
inputMethodHints: Qt.ImhNoPredictiveText |
| 40 |
} |
| 41 |
|
| 42 |
Text { |
| 43 |
text: "<b>" + i18n.tr("Issuer") + ":</b> " + uriJson.issuer |
| 44 |
color: theme.palette.normal.overlayText |
| 45 |
} |
| 46 |
|
| 47 |
Text { |
| 48 |
text: "<b>" + i18n.tr("User") + ":</b> " + uriJson.label |
| 49 |
color: theme.palette.normal.overlayText |
| 50 |
} |
| 51 |
|
| 52 |
Text { |
| 53 |
text: "<b>" + i18n.tr("Algorithm") + ":</b> " + uriJson.algorithm |
| 54 |
color: theme.palette.normal.overlayText |
| 55 |
} |
| 56 |
|
| 57 |
Row { |
| 58 |
spacing: units.gu(2) |
| 59 |
|
| 60 |
Text { |
| 61 |
text: "<b>" + i18n.tr("Password Length") + ":</b> " + uriJson.digits |
| 62 |
color: theme.palette.normal.overlayText |
| 63 |
} |
| 64 |
|
| 65 |
Text { |
| 66 |
id: keyPeriod |
| 67 |
visible: uriJson.counter == undefined |
| 68 |
text: "<b>" + i18n.tr("Interval") + ":</b> " + uriJson.period |
| 69 |
color: theme.palette.normal.overlayText |
| 70 |
} |
| 71 |
|
| 72 |
Text { |
| 73 |
visible: !keyPeriod.visible |
| 74 |
text: "<b>" + i18n.tr("Counter") + ":</b> " + uriJson.counter |
| 75 |
color: theme.palette.normal.overlayText |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
Text { |
| 80 |
text: "<b>" + i18n.tr("Key") + ":</b> " + uriJson.secret.b32 |
| 81 |
color: theme.palette.normal.overlayText |
| 82 |
wrapMode: Text.WrapAnywhere |
| 83 |
} |
| 84 |
|
| 85 |
Button { |
| 86 |
text: i18n.tr("Add") |
| 87 |
color: theme.palette.normal.positive |
| 88 |
onClicked: addKey() |
| 89 |
} |
| 90 |
|
| 91 |
Button { |
| 92 |
text: i18n.tr("Cancel") |
| 93 |
onClicked: closingPop() |
| 94 |
} |
| 95 |
|
| 96 |
function addKey() { |
| 97 |
KeysDB.storeKey( Date(), uriToRender, userDdescription.text); |
| 98 |
root.initDB(); |
| 99 |
renderUri.hide(); |
| 100 |
} |
| 101 |
|
| 102 |
function closingPop() { |
| 103 |
renderUri.hide(); |
| 104 |
} |
| 105 |
|
| 106 |
Component.onCompleted: { |
| 107 |
uriJson = OTPAuth.URI.parse(root.uriToRender); |
| 108 |
show(); |
| 109 |
} |
| 110 |
|
| 111 |
Component.onDestruction: { |
| 112 |
//To be used when PopupBase is closed |
| 113 |
} |
| 114 |
|
| 115 |
} |