Move token renew, log out, etc to Me page, closes #17.
This commit is contained in:
parent
5be2bf0779
commit
39ab714460
21
src/main.js
21
src/main.js
|
@ -19,6 +19,7 @@ import { getSealStatus } from './api.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
HomePage,
|
HomePage,
|
||||||
|
MePage,
|
||||||
TOTPViewPage,
|
TOTPViewPage,
|
||||||
NewTOTPPage,
|
NewTOTPPage,
|
||||||
LoginPage,
|
LoginPage,
|
||||||
|
@ -39,6 +40,7 @@ import {
|
||||||
|
|
||||||
const pages = {
|
const pages = {
|
||||||
HOME: new HomePage(),
|
HOME: new HomePage(),
|
||||||
|
ME: new MePage(),
|
||||||
TOTP: new TOTPViewPage(),
|
TOTP: new TOTPViewPage(),
|
||||||
NEW_TOTP: new NewTOTPPage(),
|
NEW_TOTP: new NewTOTPPage(),
|
||||||
LOGIN: new LoginPage(),
|
LOGIN: new LoginPage(),
|
||||||
|
@ -73,7 +75,8 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||||
document.body.appendChild(makeElement({
|
document.body.appendChild(makeElement({
|
||||||
tag: "nav",
|
tag: "nav",
|
||||||
class: ["uk-navbar", "uk-navbar-container"],
|
class: ["uk-navbar", "uk-navbar-container"],
|
||||||
children: makeElement({
|
children: [
|
||||||
|
makeElement({
|
||||||
tag: "div",
|
tag: "div",
|
||||||
class: "uk-navbar-left",
|
class: "uk-navbar-left",
|
||||||
children: makeElement({
|
children: makeElement({
|
||||||
|
@ -97,7 +100,23 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||||
})),
|
})),
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
}),
|
||||||
|
makeElement({
|
||||||
|
tag: "div",
|
||||||
|
class: "uk-navbar-right",
|
||||||
|
children: makeElement({
|
||||||
|
tag: "ul",
|
||||||
|
class: "uk-navbar-nav",
|
||||||
|
children: [
|
||||||
|
ListItem(makeElement({
|
||||||
|
tag: "a",
|
||||||
|
text: "Me",
|
||||||
|
onclick: _ => { changePage("ME"); }
|
||||||
|
}))
|
||||||
|
]
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
]
|
||||||
}));
|
}));
|
||||||
document.body.appendChild(makeElement({
|
document.body.appendChild(makeElement({
|
||||||
tag: "div",
|
tag: "div",
|
||||||
|
|
|
@ -2,9 +2,8 @@ import { Page } from "../types/Page.js";
|
||||||
import { setErrorText, changePage } from "../pageUtils.js";
|
import { setErrorText, changePage } from "../pageUtils.js";
|
||||||
import { getAPIURL, getToken } from "../utils.js";
|
import { getAPIURL, getToken } from "../utils.js";
|
||||||
import { makeElement } from "../htmlUtils.js";
|
import { makeElement } from "../htmlUtils.js";
|
||||||
import { getSealStatus, lookupSelf, getMounts, renewSelf } from "../api.js";
|
import { getSealStatus, lookupSelf, getMounts } from "../api.js";
|
||||||
import formatDistance from 'date-fns/formatDistance';
|
import formatDistance from 'date-fns/formatDistance';
|
||||||
import ClipboardJS from "clipboard";
|
|
||||||
|
|
||||||
export class HomePage extends Page {
|
export class HomePage extends Page {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -39,44 +38,6 @@ export class HomePage extends Page {
|
||||||
text: `VaultURL: ${getAPIURL()}`
|
text: `VaultURL: ${getAPIURL()}`
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
makeElement({
|
|
||||||
tag: "li",
|
|
||||||
children: makeElement({
|
|
||||||
tag: "a",
|
|
||||||
text: "Log Out",
|
|
||||||
onclick: () => {
|
|
||||||
localStorage.removeItem("token");
|
|
||||||
changePage(pageState.currentPage);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
makeElement({
|
|
||||||
tag: "li",
|
|
||||||
children: makeElement({
|
|
||||||
tag: "a",
|
|
||||||
text: "Copy Token",
|
|
||||||
attributes: {
|
|
||||||
"data-clipboard-text": getToken(),
|
|
||||||
},
|
|
||||||
thenRun: (e) => {
|
|
||||||
new ClipboardJS(e);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
makeElement({
|
|
||||||
tag: "li",
|
|
||||||
children: makeElement({
|
|
||||||
tag: "a",
|
|
||||||
text: "Renew Lease",
|
|
||||||
onclick: () => {
|
|
||||||
renewSelf().then(() => {
|
|
||||||
changePage("HOME");
|
|
||||||
}).catch(e => {
|
|
||||||
setErrorText(e.message);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
makeElement({
|
makeElement({
|
||||||
tag: "li",
|
tag: "li",
|
||||||
children: makeElement({
|
children: makeElement({
|
||||||
|
|
66
src/pages/Me.js
Normal file
66
src/pages/Me.js
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
import { Page } from "../types/Page.js";
|
||||||
|
import { setErrorText, setPageContent, changePage } from "../pageUtils.js";
|
||||||
|
import { makeElement } from "../htmlUtils.js";
|
||||||
|
import { getToken } from "../utils.js";
|
||||||
|
import { renewSelf } from "../api.js";
|
||||||
|
import ClipboardJS from "clipboard";
|
||||||
|
|
||||||
|
|
||||||
|
export class MePage extends Page {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
goBack() {
|
||||||
|
changePage("HOME");
|
||||||
|
}
|
||||||
|
async render() {
|
||||||
|
setPageContent(makeElement({
|
||||||
|
tag: "ul",
|
||||||
|
class: "uk-nav",
|
||||||
|
children: [
|
||||||
|
makeElement({
|
||||||
|
tag: "li",
|
||||||
|
children: makeElement({
|
||||||
|
tag: "a",
|
||||||
|
text: "Log Out",
|
||||||
|
onclick: () => {
|
||||||
|
localStorage.removeItem("token");
|
||||||
|
changePage("HOME");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
makeElement({
|
||||||
|
tag: "li",
|
||||||
|
children: makeElement({
|
||||||
|
tag: "a",
|
||||||
|
text: "Copy Token",
|
||||||
|
attributes: {
|
||||||
|
"data-clipboard-text": getToken(),
|
||||||
|
},
|
||||||
|
thenRun: (e) => {
|
||||||
|
new ClipboardJS(e);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
makeElement({
|
||||||
|
tag: "li",
|
||||||
|
children: makeElement({
|
||||||
|
tag: "a",
|
||||||
|
text: "Renew Lease",
|
||||||
|
onclick: () => {
|
||||||
|
renewSelf().then(() => {
|
||||||
|
changePage("HOME");
|
||||||
|
}).catch(e => {
|
||||||
|
setErrorText(e.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
get name() {
|
||||||
|
return "Me";
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
export { HomePage } from "./Home.js";
|
export { HomePage } from "./Home.js";
|
||||||
|
export { MePage } from "./Me.js";
|
||||||
export { TOTPViewPage } from "./TOTP/TOTPView.js";
|
export { TOTPViewPage } from "./TOTP/TOTPView.js";
|
||||||
export { NewTOTPPage } from "./TOTP/NewTOTP.js";
|
export { NewTOTPPage } from "./TOTP/NewTOTP.js";
|
||||||
export { LoginPage } from "./Login.js";
|
export { LoginPage } from "./Login.js";
|
||||||
|
|
Loading…
Reference in a new issue