workaround logout bug

This commit is contained in:
AJ ONeal 2018-08-20 17:42:59 +00:00
parent ec65fe31cc
commit 168b2edfd6
2 changed files with 65 additions and 47 deletions

View File

@ -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>

View File

@ -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,12 +29,10 @@
, 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 app = new Vue({ var vueMethods = {
el: '.v-app'
, data: vueData
, methods: {
challengeDns: function () { challengeDns: function () {
// we could do a checkbox // we could do a checkbox
var wildcard = vueData.newDomainWildcard || false; var wildcard = vueData.newDomainWildcard || false;
@ -68,7 +66,21 @@
, challengeEmail: function () { , challengeEmail: function () {
console.log("A new (Email) challenger!", vueData); 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({
el: '.v-app'
, data: vueData
, methods: vueMethods
}); });
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;