From 419fd60f756555ea7ad163c5d734f6a22d3bd6d9 Mon Sep 17 00:00:00 2001 From: aj Date: Fri, 25 Aug 2017 01:40:22 +0000 Subject: [PATCH] chimney (burning the logs) and combo box fixes --- js/controllers/login-controller.js | 23 +++++++-------- js/controllers/website-controller.js | 44 +++++++++------------------- js/services/auth-service.js | 18 +++++------- templates/partials/header.html | 10 +++---- templates/splash-page.html | 2 +- 5 files changed, 38 insertions(+), 59 deletions(-) diff --git a/js/controllers/login-controller.js b/js/controllers/login-controller.js index bcca67c..9e06ebf 100644 --- a/js/controllers/login-controller.js +++ b/js/controllers/login-controller.js @@ -5,10 +5,12 @@ app.controller('loginCtrl', [ var vm = this; vm.independentIssuer = false; - vm.oauth3 = Oauth3.oauth3 = Oauth3.oauth3 || Oauth3.create(location); + // TODO reuse most recent issuer? + vm.newOauth3 = Oauth3.create(location); vm.timers = {}; vm.defaultIssuer = 'provider.' + location.host.replace(/^cloud\./, ''); + vm.Auth = Auth; vm.session = Auth.session; vm.sessions = Auth.sessions; @@ -50,19 +52,16 @@ app.controller('loginCtrl', [ } return Oauth3.discover(url, { client_uri: Oauth3.clientUri(location) }).then(function (deets) { - console.log('discover', url); - console.log(deets); vm.currentIssuer = url; vm.issuerName = url; - return vm.oauth3.setIdentityProvider(url).then(function (deets) { - vm.oauth3.setResourceProvider(url); + return vm.newOauth3.setIdentityProvider(url).then(function (deets) { + vm.newOauth3.setResourceProvider(url); vm.spinner = false; // TODO add icon and name to directives - console.log(deets); }); }, function () { - console.log('oauth3 timeout: No dice, no change'); + console.log("oauth3 discover timeout: No dice, no change for '" + url + "'"); vm.spinner = false; }); }; @@ -77,7 +76,7 @@ app.controller('loginCtrl', [ vm.setAudience = function (url) { url = url || vm.audienceUrl; vm.audienceName = url; - vm.oauth3.setResourceProvider(url); + vm.newOauth3.setResourceProvider(url); }; vm.selectSession = function (session) { @@ -85,7 +84,6 @@ app.controller('loginCtrl', [ vm.session = session; return Auth.select(session).then(function (oauth3) { vm.xauth = false; - vm.oauth3 = oauth3; }); }; @@ -100,11 +98,10 @@ app.controller('loginCtrl', [ vm.auth = function () { var subject = vm.currentSubject; var issuer = vm.issuerName; - return vm.oauth3.authenticate({ + return vm.newOauth3.authenticate({ subject: subject , scope: [ 'domains@oauth3.org', 'domains', 'dns@oauth3.org', 'dns', 'www@daplie.com' ] }).then(function (session) { - console.log('vm.auth session.issuer', session.issuer); session.subject = subject; session.issuer = issuer; Auth.add(session); @@ -114,8 +111,8 @@ app.controller('loginCtrl', [ $location.path('/' + $rootScope.redirectedURL); } }, function (err) { - console.log('auth error'); - console.log(err); + console.error('auth error'); + console.error(err); }); }; diff --git a/js/controllers/website-controller.js b/js/controllers/website-controller.js index badaff2..b98beb8 100644 --- a/js/controllers/website-controller.js +++ b/js/controllers/website-controller.js @@ -20,7 +20,8 @@ function handleFiles(ev) { vm.unzip = vm.isZip; vm.stripZip = vm.isZip; $scope.$digest(); - console.log('vm.currentFiles', vm.currentFiles); + console.log('[handleFiles] vm.currentFiles:'); + console.log(vm.currentFiles); } window.document.body.addEventListener('change', handleFiles); @@ -98,12 +99,12 @@ app.controller('websiteCtrl', [ }; vm.selectDomain = function (domain) { - vm.domain = domain; - vm.newDomain = domain.domain; + vm.domain = domain; //vm.selectedDomain.description; + vm.newDomain = vm.domain.domain; return Auth.api('dns.list', { }).then(function (records) { records = records.filter(function (r) { - return /^A(AAA)?$/i.test(r.type) && ((r.sld + '.' + r.tld) === domain || r.zone === domain.domain); + return /^A(AAA)?$/i.test(r.type) && ((r.sld + '.' + r.tld) === vm.domain.domain || r.zone === vm.domain.domain); }); vm.records = records; records.forEach(function (record) { @@ -114,7 +115,8 @@ app.controller('websiteCtrl', [ } } }); - console.log('dns records', records); + console.log('[selectDomain] dns records:'); + console.log(records); }); }; @@ -128,8 +130,8 @@ app.controller('websiteCtrl', [ vm.record = { sub: sub, host: (sub ? sub + '.' : '') + vm.domain.domain }; vm.currentHost = vm.record.host; - console.log('vm.record', vm.record); - console.log('vm.currentHost', vm.currentHost); + console.log('[setRecord] vm.record:'); + console.log(vm.record); }; vm.selectRecord = function (record) { @@ -160,9 +162,6 @@ app.controller('websiteCtrl', [ vm.Sites = {}; vm.Sites.create = function () { - console.log('##### Auth.oauth3'); - console.log(Auth.oauth3); - var pkg = Auth.oauth3.pkg('www@daplie.com'); var parts; var sub; @@ -217,31 +216,19 @@ app.controller('websiteCtrl', [ var sess; var prom; var def; - console.log('[pkg www] request domain'); - console.log(result.data); - - console.log('[pkg www] vm.domain.session:'); - console.log(vm.domain.session); - - console.log(vm.currentHost, vm.domain.domain); - console.log(vm._isSubDomain(vm.currentHost, vm.domain.domain)); // can validate automatically if (vm.domain.session && vm._isSubDomain(vm.currentHost, vm.domain.domain)) { // this should always succeed Auth.sessions.some(function (session) { - console.log('#', session.token.sub + '@' + session.token.iss); if (vm.domain.session === (session.token.sub + '@' + session.token.iss)) { - console.log('=', session.token.sub + '@' + session.token.iss); sess = session; return session; } }); if (sess) { - console.log('[pkg www] session selected', sess); prom = Auth.get(sess).then(function (oauth3) { - console.log('[pkg www] instance selected', oauth3); return oauth3.api('dns.set', { sld: sld, tld: tld, sub: ('' + result.data.prefix), type: 'TXT', ttl: 300, value: result.data.challenge }); }); } @@ -260,10 +247,7 @@ app.controller('websiteCtrl', [ } return prom.then(function () { - console.log('[pkg www] after pkg'); - console.log(pkg); return pkg.claim(domainReq).then(function (result) { - console.log('[pkg www] claim', result); return vm._createWebsite(pkg); }); }); @@ -310,7 +294,6 @@ app.controller('websiteCtrl', [ return $q.all(Auth.sessions.map(function (session) { - console.log('[www] select'); return Auth.get(session).then(function (oauth3) { var pkg = oauth3.pkg('www@daplie.com'); @@ -330,7 +313,7 @@ app.controller('websiteCtrl', [ }); }); })).then(function () { - console.log('[www] sites'); + console.log('[listSites] sites:'); console.log(sites); vm.sites = sites; }); @@ -338,7 +321,8 @@ app.controller('websiteCtrl', [ //vm.getDomains(); Auth.api('domains.list', {}).then(function (els) { - console.log('domains.list els', els); + console.log('[init] domains.list els:'); + console.log(els); vm.domains = els; $scope.domain = vm.domains; }); @@ -351,9 +335,9 @@ app.controller('websiteCtrl', [ }, 0); }; - $scope.$watch('vm.selectedDomain', function(domainSelected) { + $scope.$watch('vm.selectedDomain', function (domainSelected) { if (domainSelected !== undefined) { - vm.selectDomain(vm.selectedDomain.title); + vm.selectDomain(vm.selectedDomain.description); } }); diff --git a/js/services/auth-service.js b/js/services/auth-service.js index 7acba02..7331351 100644 --- a/js/services/auth-service.js +++ b/js/services/auth-service.js @@ -25,8 +25,6 @@ app.factory('Auth', [ var obj = JSON.parse(localStorage.getItem(dapSessions) || 'null') || {}; var dapName = 'dap-' + session.subject + '|' + session.issuer; - console.log('add session', session); - /* Object.keys(Auth.session).forEach(function (key) { delete Auth.session[key]; @@ -64,9 +62,17 @@ app.factory('Auth', [ Auth.sessions.push(session); }); + + if (Auth.session) { + Auth.select(Auth.session); + } return Auth.session; } , get: function (session) { + if (!session) { + return $q.resolve(null); + } + if (!session.issuer) { throw new Error("session doesn't have an issuer"); } @@ -83,20 +89,12 @@ app.factory('Auth', [ , audience: session.audience || session.issuer , session: session }).then(function () { - console.log('a Auth._oauth3s[name]', Auth._oauth3s[name]); - console.log('_resourceProviderDirectives', Auth._oauth3s[name]._resourceProviderDirectives); return sess; }); } else { - console.log('b Auth._oauth3s[name]', Auth._oauth3s[name]); - console.log('_resourceProviderDirectives', Auth._oauth3s[name]._resourceProviderDirectives); promise = Oauth3.PromiseA.resolve(Auth._oauth3s[name]); } - console.log('session.issuer:', session.issuer); - console.log('session.subject:', session.subject); - console.log('session:', session); - return promise; } , select: function (session) { diff --git a/templates/partials/header.html b/templates/partials/header.html index 2c0cb1a..c3afc39 100644 --- a/templates/partials/header.html +++ b/templates/partials/header.html @@ -18,20 +18,20 @@