browse multiple sessions
This commit is contained in:
parent
1ccf0dd71c
commit
a55aac6fc1
|
@ -1 +1 @@
|
|||
Subproject commit 9a7aa3261f2ad97ebd436c8b1e86d168cf93023d
|
||||
Subproject commit 8961a4e51962a21690b5e68af3abaad24be8207c
|
|
@ -81,11 +81,11 @@ app.controller('loginCtrl', [
|
|||
};
|
||||
|
||||
vm.selectSession = function (session) {
|
||||
vm.xauth = true;
|
||||
vm.session = session;
|
||||
vm.oauth3.init({
|
||||
location: location
|
||||
, issuer: session.issuer
|
||||
, audience: session.audience || session.issuer
|
||||
return Auth.select(session).then(function (oauth3) {
|
||||
vm.xauth = false;
|
||||
vm.oauth3 = oauth3;
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -4,6 +4,30 @@ app.controller('websiteCtrl', [
|
|||
|
||||
var vm = this;
|
||||
vm.oauth3 = Auth.oauth3;
|
||||
vm.domains = [];
|
||||
|
||||
Auth.sessions.forEach(function (session) {
|
||||
return Auth.select(session).then(function (oauth3) {
|
||||
return oauth3.api('domains.list', {}).then(function (domains) {
|
||||
if (domains.error) {
|
||||
// not all tokens support all apis
|
||||
return;
|
||||
}
|
||||
if (!Array.isArray(domains)) {
|
||||
console.error('domains are not domains');
|
||||
console.error(domains);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('domains');
|
||||
console.log(domains);
|
||||
domains.forEach(function (domain) {
|
||||
domain.session = session.token.sub + '@' + session.token.iss;
|
||||
vm.domains.push(domain);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
vm.getDomains = function () {
|
||||
vm.oauth3.api('domains.list', {}).then(function (result) {
|
||||
|
@ -11,8 +35,28 @@ app.controller('websiteCtrl', [
|
|||
});
|
||||
};
|
||||
|
||||
vm.setDomain = function () {
|
||||
if (!vm.domains || !vm.domains.length) {
|
||||
vm.domain = { domain: vm.newDomain };
|
||||
return;
|
||||
}
|
||||
|
||||
vm.domains.some(function (domain) {
|
||||
if (domain.domain === vm.newDomain) {
|
||||
vm.domain = domain;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!vm.domain) {
|
||||
vm.domain = { domain: vm.newDomain };
|
||||
}
|
||||
};
|
||||
|
||||
vm.selectDomain = function (domain) {
|
||||
vm.domain = domain;
|
||||
vm.newDomain = domain.domain;
|
||||
/*
|
||||
return vm.oauth3.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);
|
||||
|
@ -21,6 +65,7 @@ app.controller('websiteCtrl', [
|
|||
console.log('records');
|
||||
console.log(records);
|
||||
});
|
||||
*/
|
||||
};
|
||||
|
||||
vm.selectRecord = function (record) {
|
||||
|
|
|
@ -23,8 +23,16 @@ app.factory('Auth', [
|
|||
var obj = JSON.parse(localStorage.getItem(dapSessions) || 'null') || {};
|
||||
var dapName = 'dap-' + session.subject + '|' + session.issuer;
|
||||
|
||||
console.log('session', session);
|
||||
console.log('add session', session);
|
||||
|
||||
/*
|
||||
Object.keys(Auth.session).forEach(function (key) {
|
||||
delete Auth.session[key];
|
||||
});
|
||||
Object.keys(session).forEach(function (key) {
|
||||
Auth.session[key] = session[key];
|
||||
});
|
||||
*/
|
||||
Auth.session = session;
|
||||
Auth.sessions.push(session);
|
||||
|
||||
|
@ -53,6 +61,28 @@ app.factory('Auth', [
|
|||
|
||||
return Auth.session;
|
||||
}
|
||||
, select: function (session) {
|
||||
var name = session.token.sub + '@' + session.token.iss;
|
||||
var promise;
|
||||
|
||||
if (!Auth._oauth3s[name]) {
|
||||
Auth._oauth3s[name] = Oauth3.create(window.location);
|
||||
promise = Auth._oauth3s[name].init({
|
||||
location: location
|
||||
, issuer: session.issuer
|
||||
, audience: session.audience || session.issuer
|
||||
, session: session
|
||||
}).then(function () {
|
||||
console.log('a Auth._oauth3s[name]', Auth._oauth3s[name]);
|
||||
return Auth._oauth3s[name];
|
||||
});
|
||||
} else {
|
||||
console.log('b Auth._oauth3s[name]', Auth._oauth3s[name]);
|
||||
promise = Oauth3.PromiseA.resolve(Auth._oauth3s[name]);
|
||||
}
|
||||
|
||||
return promise;
|
||||
}
|
||||
, signOut: function () {
|
||||
var session = Auth.session;
|
||||
var dapName = 'dap-' + session.subject + '|' + session.issuer;
|
||||
|
@ -75,6 +105,7 @@ app.factory('Auth', [
|
|||
});
|
||||
// localStorage.clear();
|
||||
}
|
||||
, _oauth3s: {}
|
||||
, sessions: []
|
||||
, session: null
|
||||
, oauth3: null
|
||||
|
|
|
@ -14,14 +14,14 @@
|
|||
<input type="text" class="form-control" placeholder="www" />
|
||||
<span class="input-group-addon">.</span>
|
||||
|
||||
<input type="text" class="form-control" placeholder="Select a domain" aria-label="Domain Name">
|
||||
<input type="text" class="form-control" placeholder="Select a domain" aria-label="Domain Name" ng-model="vm.newDomain" ng-change="vm.setDomain()">
|
||||
<div class="input-group-btn">
|
||||
<!-- Single button -->
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="#">blog.jane.smith.net</a></li>
|
||||
<li ng-repeat="domain in vm.domains"><button class="btn btn-link" ng-bind="domain.domain" ng-click="vm.selectDomain(domain)">example.com</button></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue