From 37734638b863fb24991db0c1554c70fb0dae7fe5 Mon Sep 17 00:00:00 2001 From: aj Date: Wed, 23 Aug 2017 18:54:50 +0000 Subject: [PATCH] fix some state issues --- js/controllers/website-controller.js | 8 +++----- js/services/auth-service.js | 14 +++++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/js/controllers/website-controller.js b/js/controllers/website-controller.js index ed57432..e5a4d3e 100644 --- a/js/controllers/website-controller.js +++ b/js/controllers/website-controller.js @@ -31,7 +31,7 @@ app.controller('websiteCtrl', [ return $q.all(Auth.sessions.map(function (session) { - return Auth.select(session).then(function (oauth3) { + return Auth.get(session).then(function (oauth3) { return oauth3.api(apiname, {}).then(function (collection) { @@ -201,7 +201,7 @@ app.controller('websiteCtrl', [ if (sess) { console.log('[pkg www] session selected', sess); - prom = Auth.select(sess).then(function (oauth3) { + 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 }); }); @@ -238,10 +238,8 @@ app.controller('websiteCtrl', [ return $q.all(Auth.sessions.map(function (session) { console.log('[www] select'); - return Auth.select(session).then(function (oauth3) { - console.log('[www] oauth3', oauth3._resourceProviderDirectives); + return Auth.get(session).then(function (oauth3) { var pkg = oauth3.pkg('www@daplie.com'); - console.log('[www] post pkg', oauth3._resourceProviderDirectives); return pkg.list().then(function (result) { var _sites = result.data; diff --git a/js/services/auth-service.js b/js/services/auth-service.js index 0bc7791..7acba02 100644 --- a/js/services/auth-service.js +++ b/js/services/auth-service.js @@ -66,7 +66,7 @@ app.factory('Auth', [ }); return Auth.session; } - , select: function (session) { + , get: function (session) { if (!session.issuer) { throw new Error("session doesn't have an issuer"); } @@ -97,12 +97,16 @@ app.factory('Auth', [ console.log('session.subject:', session.subject); console.log('session:', session); - promise.then(function (oauth3) { + return promise; + } + , select: function (session) { + return Auth.get(session).then(function (oauth3) { + var dapName = 'dap-' + session.subject + '|' + session.issuer; + localStorage.setItem(dapSession, dapName); + Auth.session = session; Auth.oauth3 = oauth3; - }) - - return promise; + }); } , signOut: function () { var session = Auth.session;