workaround logout bug
This commit is contained in:
parent
ec65fe31cc
commit
168b2edfd6
|
@ -5,27 +5,30 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="v-app">
|
<div class="v-app">
|
||||||
|
<div v-if="spinner" style="position: absolute; width: 100%; height: 100%; background-color: #ddd;">Loading... </div>
|
||||||
|
|
||||||
<div v-if="!hasAccount">
|
<div v-if="!hasAccount">
|
||||||
<h1>Login</h1>
|
<h1>Login</h1>
|
||||||
<form class="js-auth-form">
|
<form class="js-auth-form" v-on:submit.prevent="login()">
|
||||||
<input class="js-auth-subject" placeholder="email" type="email" required/>
|
<input class="js-auth-subject" v-model="newEmail" placeholder="email" type="email" required/>
|
||||||
<button class="js-auth-submit" type="submit">Login</button>
|
<button class="js-auth-submit" type="submit">Login</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="hasAccount">
|
<div v-if="hasAccount">
|
||||||
<h1>Account</h1>
|
<h1>Account</h1>
|
||||||
|
<button v-on:click.prevent.stop="logout()" type="click">Logout</button>
|
||||||
<form v-on:submit.prevent="challengeDns()">
|
<form v-on:submit.prevent="challengeDns()">
|
||||||
Add a custom domain:
|
Add a custom domain:
|
||||||
<input v-model="newDomain" placeholder="example.com" type="text" required/>
|
<input v-model="newDomain" placeholder="example.com" type="text" required/>
|
||||||
<button type="submit">Next</button>
|
<button type="submit">Next</button>
|
||||||
</form>
|
</form>
|
||||||
<form v-on:submit.prevent="challengeEmail()">
|
<!-- not yet -->
|
||||||
|
<!--form v-on:submit.prevent="challengeEmail()">
|
||||||
Authorize another email:
|
Authorize another email:
|
||||||
<input v-model="newEmail" placeholder="jon@example.com" type="email" required/>
|
<input v-model="newEmail" placeholder="jon@example.com" type="email" required/>
|
||||||
<button type="submit">Next</button>
|
<button type="submit">Next</button>
|
||||||
</form>
|
</form-->
|
||||||
<h3>Claims</h3>
|
<h3>Claims</h3>
|
||||||
<p>If your DNS host supports ANAME records, please use those instead of CNAMEs.</p>
|
<p>If your DNS host supports ANAME records, please use those instead of CNAMEs.</p>
|
||||||
<p>If CNAMEs are not supported, set an A record to {{ site.deviceDomainA }}.</p>
|
<p>If CNAMEs are not supported, set an A record to {{ site.deviceDomainA }}.</p>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
host: window.location.host
|
host: window.location.host
|
||||||
, pathname: window.location.pathname.replace(/\/[^\/]*$/, '/')
|
, pathname: window.location.pathname.replace(/\/[^\/]*$/, '/')
|
||||||
});
|
});
|
||||||
var $ = function () { return document.querySelector.apply(document, arguments); };
|
//var $ = function () { return document.querySelector.apply(document, arguments); };
|
||||||
var sessionStr = localStorage.getItem('session');
|
var sessionStr = localStorage.getItem('session');
|
||||||
var session;
|
var session;
|
||||||
if (sessionStr) {
|
if (sessionStr) {
|
||||||
|
@ -29,46 +29,58 @@
|
||||||
, newEmail: null
|
, newEmail: null
|
||||||
, hasAccount: false
|
, hasAccount: false
|
||||||
, token: null
|
, token: null
|
||||||
|
, spinner: false
|
||||||
, site: { deviceDomain: document.location.hostname, deviceDomainA: dnsRecords[document.location.hostname] }
|
, site: { deviceDomain: document.location.hostname, deviceDomainA: dnsRecords[document.location.hostname] }
|
||||||
};
|
};
|
||||||
|
var vueMethods = {
|
||||||
|
challengeDns: function () {
|
||||||
|
// we could do a checkbox
|
||||||
|
var wildcard = vueData.newDomainWildcard || false;
|
||||||
|
if (!/(\*\.)?[a-z0-9][a-z0-9\.\-_]\.[a-z0-9]{2,}/.test(vueData.newDomain)) {
|
||||||
|
window.alert("invalid domain name '" + vueData.newDomain + "'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// we can just detect by text
|
||||||
|
if ('*.' === vueData.newDomain.slice(0, 2)) {
|
||||||
|
vueData.newDomain = vueData.newDomain.slice(2);
|
||||||
|
wildcard = true;
|
||||||
|
}
|
||||||
|
return oauth3.request({
|
||||||
|
url: 'https://api.' + location.hostname + '/api/telebit.cloud/account/authorizations/new'
|
||||||
|
, method: 'POST'
|
||||||
|
, session: session
|
||||||
|
, data: { type: 'dns', value: vueData.newDomain, wildcard: wildcard }
|
||||||
|
}).then(function (resp) {
|
||||||
|
vueData.claims.unshift(resp.data.claim);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
, checkDns: function (claim) {
|
||||||
|
return oauth3.request({
|
||||||
|
url: 'https://api.' + location.hostname + '/api/telebit.cloud/account/authorizations/new/:value/:challenge'
|
||||||
|
.replace(/:value/g, claim.value)
|
||||||
|
.replace(/:challenge/g, claim.challenge)
|
||||||
|
, method: 'POST'
|
||||||
|
, session: session
|
||||||
|
});
|
||||||
|
}
|
||||||
|
, challengeEmail: function () {
|
||||||
|
console.log("A new (Email) challenger!", vueData);
|
||||||
|
}
|
||||||
|
, login: function () {
|
||||||
|
var email = vueData.newEmail;
|
||||||
|
vueMethods.logout();
|
||||||
|
onClickLogin(email);
|
||||||
|
}
|
||||||
|
, logout: function () {
|
||||||
|
sessionStorage.clear();
|
||||||
|
vueData.hasAccount = false;
|
||||||
|
// TODO OAUTH3._logoutHelper(directives, opts)
|
||||||
|
}
|
||||||
|
};
|
||||||
var app = new Vue({
|
var app = new Vue({
|
||||||
el: '.v-app'
|
el: '.v-app'
|
||||||
, data: vueData
|
, data: vueData
|
||||||
, methods: {
|
, methods: vueMethods
|
||||||
challengeDns: function () {
|
|
||||||
// we could do a checkbox
|
|
||||||
var wildcard = vueData.newDomainWildcard || false;
|
|
||||||
if (!/(\*\.)?[a-z0-9][a-z0-9\.\-_]\.[a-z0-9]{2,}/.test(vueData.newDomain)) {
|
|
||||||
window.alert("invalid domain name '" + vueData.newDomain + "'");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// we can just detect by text
|
|
||||||
if ('*.' === vueData.newDomain.slice(0, 2)) {
|
|
||||||
vueData.newDomain = vueData.newDomain.slice(2);
|
|
||||||
wildcard = true;
|
|
||||||
}
|
|
||||||
return oauth3.request({
|
|
||||||
url: 'https://api.' + location.hostname + '/api/telebit.cloud/account/authorizations/new'
|
|
||||||
, method: 'POST'
|
|
||||||
, session: session
|
|
||||||
, data: { type: 'dns', value: vueData.newDomain, wildcard: wildcard }
|
|
||||||
}).then(function (resp) {
|
|
||||||
vueData.claims.unshift(resp.data.claim);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
, checkDns: function (claim) {
|
|
||||||
return oauth3.request({
|
|
||||||
url: 'https://api.' + location.hostname + '/api/telebit.cloud/account/authorizations/new/:value/:challenge'
|
|
||||||
.replace(/:value/g, claim.value)
|
|
||||||
.replace(/:challenge/g, claim.challenge)
|
|
||||||
, method: 'POST'
|
|
||||||
, session: session
|
|
||||||
});
|
|
||||||
}
|
|
||||||
, challengeEmail: function () {
|
|
||||||
console.log("A new (Email) challenger!", vueData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
app = null;
|
app = null;
|
||||||
|
|
||||||
|
@ -121,13 +133,9 @@
|
||||||
|
|
||||||
// This opens up the login window for the specified provider
|
// This opens up the login window for the specified provider
|
||||||
//
|
//
|
||||||
function onClickLogin(ev) {
|
function onClickLogin(email) {
|
||||||
ev.preventDefault();
|
|
||||||
ev.stopPropagation();
|
|
||||||
|
|
||||||
var email = $('.js-auth-subject').value;
|
|
||||||
|
|
||||||
// TODO check subject for provider viability
|
// TODO check subject for provider viability
|
||||||
|
vueData.spinner = true;
|
||||||
return oauth3.authenticate({
|
return oauth3.authenticate({
|
||||||
subject: email
|
subject: email
|
||||||
, scope: 'email@oauth3.org'
|
, scope: 'email@oauth3.org'
|
||||||
|
@ -168,10 +176,17 @@
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
console.error('Authentication Failed:');
|
console.error('Authentication Failed:');
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
}).then(function () {
|
||||||
|
vueData.spinner = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$('body form.js-auth-form').addEventListener('submit', onClickLogin);
|
//$('body form.js-auth-form').addEventListener('submit', function onClickLoginHelper(ev) {
|
||||||
|
// ev.preventDefault();
|
||||||
|
// ev.stopPropagation();
|
||||||
|
// var email = $('.js-auth-subject').value;
|
||||||
|
// onClickLogin(email);
|
||||||
|
//});
|
||||||
onChangeProvider('oauth3.org');
|
onChangeProvider('oauth3.org');
|
||||||
if (session) {
|
if (session) {
|
||||||
vueData.token = session.access_token;
|
vueData.token = session.access_token;
|
||||||
|
|
Loading…
Reference in New Issue