1
0
Fork 0
VaultUI/src/pages/TOTP/NewTOTP.js

98 lines
2.6 KiB
JavaScript
Raw Normal View History

import { Margin } from "../../elements/Margin";
import { MarginInline } from "../../elements/MarginInline";
2021-05-07 23:33:58 +01:00
import { Page } from "../../types/Page";
2021-05-07 11:53:26 +01:00
import { addNewTOTP } from "../../api/addNewTOTP";
2021-05-07 23:21:38 +01:00
import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils";
import { makeElement } from "../../htmlUtils";
2021-05-07 23:08:02 +01:00
import { pageState } from "../../globalPageState.ts";
2021-04-20 23:23:17 +01:00
import i18next from 'i18next';
2021-04-15 13:01:58 +01:00
2021-05-07 11:53:26 +01:00
2021-04-15 13:01:58 +01:00
export class NewTOTPPage extends Page {
constructor() {
super();
}
goBack() {
2021-04-17 11:24:43 +01:00
changePage("TOTP");
2021-04-15 13:01:58 +01:00
}
render() {
setTitleElement(pageState);
let totpForm = makeElement({
tag: "form",
children: [
Margin(makeElement({
tag: "input",
class: ["uk-input", "uk-form-width-medium"],
attributes: {
required: true,
type: "text",
2021-04-20 23:23:17 +01:00
placeholder: i18next.t("totp_new_name_text"),
2021-04-15 13:01:58 +01:00
name: "name"
}
})),
makeElement({
tag: "p",
2021-04-20 23:23:17 +01:00
text: i18next.t("totp_new_info")
2021-04-15 13:01:58 +01:00
}),
Margin(makeElement({
tag: "input",
class: ["uk-input", "uk-form-width-medium"],
attributes: {
type: "text",
2021-04-20 23:23:17 +01:00
placeholder: i18next.t("totp_new_uri_input"),
2021-04-15 13:01:58 +01:00
name: "uri"
}
})),
Margin(makeElement({
tag: "input",
class: ["uk-input", "uk-form-width-medium"],
attributes: {
type: "text",
2021-04-20 23:23:17 +01:00
placeholder: i18next.t("totp_new_key_input"),
2021-04-15 13:01:58 +01:00
name: "key"
}
})),
makeElement({
tag: "p",
id: "errorText",
class: "uk-text-danger"
}),
MarginInline(makeElement({
tag: "button",
class: ["uk-button", "uk-button-primary"],
2021-04-20 23:23:17 +01:00
text: i18next.t("totp_new_add_btn"),
2021-04-15 13:01:58 +01:00
attributes: {
type: "submit"
}
}))
]
});
setPageContent(totpForm);
totpForm.addEventListener("submit", function (e) {
e.preventDefault();
let formData = new FormData(totpForm);
let parms = {
url: formData.get("uri"),
key: formData.get("key").replaceAll("-", "").replaceAll(" ", "").toUpperCase(),
2021-04-15 13:01:58 +01:00
name: formData.get("name"),
generate: false
};
2021-04-18 10:42:57 +01:00
addNewTOTP(pageState.currentBaseMount, parms).then(_ => {
2021-04-17 11:24:43 +01:00
changePage("TOTP");
2021-04-15 13:01:58 +01:00
}).catch(e => {
setErrorText(`API Error: ${e.message}`);
});
});
}
get titleSuffix() {
2021-04-20 23:23:17 +01:00
return i18next.t("totp_new_suffix");
}
2021-04-15 13:01:58 +01:00
get name() {
2021-04-20 23:23:17 +01:00
return i18next.t("totp_new_title");
2021-04-15 13:01:58 +01:00
}
}