From 856413a403df333ed691db9f258b85d6eb80869c Mon Sep 17 00:00:00 2001 From: aj Date: Mon, 14 Aug 2017 19:45:19 +0000 Subject: [PATCH] add some of the website logic --- js/controllers/websiteController.js | 42 ++++++++++++++++++++++++++++- js/www@daplie.com.js | 23 ++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 js/www@daplie.com.js diff --git a/js/controllers/websiteController.js b/js/controllers/websiteController.js index 8d1c086..b5d39ec 100644 --- a/js/controllers/websiteController.js +++ b/js/controllers/websiteController.js @@ -1,3 +1,43 @@ -app.controller('WebsiteController', [function($scope) { +app.controller('WebsiteController', [ 'azp@oauth3.org', function ($scope, Oauth3) { + var vm = this; + vm.oauth3 = Oauth3.oauth3; + + vm.getDomains = function () { + vm.oauth3.api('domains.list', {}).then(function (result) { + vm.domains = result.registrations || result; + }); + }; + + vm.selectDomain = function (domain) { + vm.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(); }]); diff --git a/js/www@daplie.com.js b/js/www@daplie.com.js new file mode 100644 index 0000000..061c87c --- /dev/null +++ b/js/www@daplie.com.js @@ -0,0 +1,23 @@ +;(function (exports) { +'use strict'; + +var OAUTH3 = exports.OAUTH3 = exports.OAUTH3 || require('./oauth3.core.js').OAUTH3; + +OAUTH3._pkgs['www@daplie.com'] = { + add: function (opts) { + var providerUri = opts.audience; + var session = opts.session; + + return OAUTH3.request({ + method: 'POST' + , url: OAUTH3.url.normalize(providerUri) + + '/api/www@daplie.com/acl/www/' + opts.hostname + , session: session + , multipart: opts.multipart // special property to be figured out by browser request code + }).then(function (res) { + return res; + }); + } +}; + +}('undefined' !== typeof exports ? exports : window));