diff --git a/lib/extensions/admin/account.html b/lib/extensions/admin/account.html index a6fc728..1fd078e 100644 --- a/lib/extensions/admin/account.html +++ b/lib/extensions/admin/account.html @@ -3,18 +3,37 @@ Telebit Account -

Login

-
- - -
-
    -
  1. - {{ domain }} -
  2. -
+ +
+

Login

+
+ + +
+
+ +
+

Account

+
+ Add a custom domain: + + +
+
+ Authorize another email: + + +
+
    +
  1. + {{ domain }} +
  2. +
+
+
+
diff --git a/lib/extensions/admin/js/account.js b/lib/extensions/admin/js/account.js index b86b12a..805d421 100644 --- a/lib/extensions/admin/js/account.js +++ b/lib/extensions/admin/js/account.js @@ -6,6 +6,77 @@ , pathname: window.location.pathname.replace(/\/[^\/]*$/, '/') }); var $ = function () { return document.querySelector.apply(document, arguments); } + var vueData = { + domains: [] + , newDomain: null + , newEmail: null + , hasAccount: false + , token: null + }; + var app = new Vue({ + el: '.v-app' + , data: vueData + , methods: { + challengeDns: function () { + console.log("A new (DNS) challenger!", vueData); + } + , challengeEmail: function () { + console.log("A new (Email) challenger!", vueData); + } + } + }); + + function listStuff(data) { + //window.alert("TODO: show authorized devices, domains, and connectivity information"); + vueData.hasAccount = true; + vueData.domains = data.domains; + } + + var sessionStr = localStorage.getItem('session'); + var session; + if (sessionStr) { + try { + session = JSON.parse(sessionStr); + } catch(e) { + // ignore + } + } + + function loadAccount(session) { + return oauth3.request({ + url: 'https://api.' + location.hostname + '/api/telebit.cloud/account' + , session: session + }).then(function (resp) { + + console.info("Telebit Account:"); + console.log(resp.data); + + if (resp.data && resp.data.domains) { + listStuff(resp.data); + return; + } + + if (1 === resp.data.accounts.length) { + listStuff(resp); + } else if (0 === resp.data.accounts.length) { + return oauth3.request({ + url: 'https://api.' + location.hostname + 'api/telebit.cloud/account' + , method: 'POST' + , session: session + , body: { + email: email + } + }).then(function (resp) { + listStuff(resp); + }); + } if (resp.data.accounts.length > 2) { + window.alert("Multiple accounts."); + } else { + window.alert("Bad response."); + } + + }); + } function onChangeProvider(providerUri) { // example https://oauth3.org @@ -35,16 +106,6 @@ // console.info('Secure PPID (aka subject):', session.token.sub); - function listStuff(data) { - //window.alert("TODO: show authorized devices, domains, and connectivity information"); - var app6 = new Vue({ - el: '.v-app', - data: { - domains: data.domains - } - }); - } - return oauth3.request({ url: 'https://api.oauth3.org/api/issuer@oauth3.org/jwks/:sub/:kid.json' .replace(/:sub/g, session.token.sub) @@ -62,41 +123,8 @@ console.info("Inspect Token:"); console.log(resp.data); - return oauth3.request({ - url: 'https://api.' + location.hostname + '/api/telebit.cloud/account' - , session: session - }).then(function (resp) { - - console.info("Telebit Account:"); - console.log(resp.data); - - if (resp.data && resp.data.domains) { - listStuff(resp.data); - return; - } - - if (1 === resp.data.accounts.length) { - listStuff(resp); - } else if (0 === resp.data.accounts.length) { - return oauth3.request({ - url: 'https://api.' + location.hostname + 'api/telebit.cloud/account' - , method: 'POST' - , session: session - , body: { - email: email - } - }).then(function (resp) { - listStuff(resp); - }); - } if (resp.data.accounts.length > 2) { - window.alert("Multiple accounts."); - } else { - window.alert("Bad response."); - } - - }); - - + localStorage.setItem('session', JSON.stringify(session)); + loadAccount(session) }); }); @@ -109,4 +137,8 @@ $('body form.js-auth-form').addEventListener('submit', onClickLogin); onChangeProvider('oauth3.org'); + if (session) { + vueData.token = session.access_token + loadAccount(session); + } }());