app.controller('websiteCtrl', [ '$scope', 'Auth', 'azp@oauth3.org' , function ($scope, Auth, Oauth3) { 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) { vm.domains = result.registrations || result; }); }; 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); }); vm.records = records; console.log('records'); console.log(records); }); */ }; vm.selectRecord = function (record) { vm.record = record; vm.currentHost = record.host; // .replace(new RegExp('\\.' + vm.domain.domain.replace(/\./g, '\\.') + '$', '')); }; vm.setFiles = function (files) { console.log('setFiles'); console.log(files); console.log(vm.newFiles); }; vm.createWebsite = function () { var fd = new window.FormData(); var pkg = vm.oauth3.pkg('www@daplie.com'); return pkg.add({ hostname: vm.currentHost, multipart: { site: vm.currentFiles[0] } }); }; //vm.getDomains(); }]);