From 7ca86c80740f2c736a8c5cfb89f7ad164d4753f3 Mon Sep 17 00:00:00 2001 From: aj Date: Fri, 29 Sep 2017 00:01:28 +0000 Subject: [PATCH 1/2] WIP own profile --- index.html | 2 + js/app.js | 25 +++- js/controllers/login-controller.js | 1 - js/controllers/profile-controller.js | 183 +++++++++++++++++++++++++++ js/issuer@oauth3.org.js | 78 ++++++++++++ templates/account-settings.html | 20 ++- templates/website.html | 25 ++-- 7 files changed, 317 insertions(+), 17 deletions(-) create mode 100644 js/controllers/profile-controller.js create mode 100644 js/issuer@oauth3.org.js diff --git a/index.html b/index.html index bc837ed..785e77f 100644 --- a/index.html +++ b/index.html @@ -26,6 +26,7 @@ + @@ -40,6 +41,7 @@ + diff --git a/js/app.js b/js/app.js index a3dd002..116352a 100644 --- a/js/app.js +++ b/js/app.js @@ -1,4 +1,24 @@ -var app = angular.module('launchpad', ['oauth3.org', 'ui.router', 'LocalStorageModule', 'angucomplete-alt']); +(function () { +'use strict'; + +var angular = window.angular; +var OAUTH3 = window.OAUTH3; + +var app = window.app = angular.module('launchpad', ['oauth3.org', 'ui.router', 'LocalStorageModule', 'angucomplete-alt']); + +app.directive('daplieFileChange', function () { + return { + restrict: 'A', + require:"ngModel", + link: function (scope, element, attrs, ngModel) { + element.bind('change', function (event) { + var files = event.target.files; + ngModel.$setViewValue(files[0]); + scope.$eval(attrs.daplieFileChange); + }); + } + }; +}); app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider', function ($stateProvider, $urlRouterProvider, localStorageServiceProvider) { @@ -106,7 +126,7 @@ app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider views: { 'content@': { templateUrl: 'templates/account-settings.html', - controller: 'loginCtrl as vm', + controller: 'profileCtrl as vm', } } }); @@ -133,3 +153,4 @@ app.run(['$rootScope', '$state', 'Auth', '$location', function($rootScope, $stat } }); }]); +}()); diff --git a/js/controllers/login-controller.js b/js/controllers/login-controller.js index 2e13dde..09499bf 100644 --- a/js/controllers/login-controller.js +++ b/js/controllers/login-controller.js @@ -148,5 +148,4 @@ app.controller('loginCtrl', [ }); }); }; - }]); diff --git a/js/controllers/profile-controller.js b/js/controllers/profile-controller.js new file mode 100644 index 0000000..f3b7b29 --- /dev/null +++ b/js/controllers/profile-controller.js @@ -0,0 +1,183 @@ +app.controller('profileCtrl', [ + '$scope', '$timeout', 'Auth', '$location', 'localStorageService', '$rootScope', 'azp@oauth3.org', '$stateParams' +, function ($scope, $timeout, Auth, $location, localStorageService, $rootScope, Oauth3, $stateParams) { + + var vm = this; + + vm.independentIssuer = false; + // 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; + + vm.showAdvanced = true; + + vm.toggleAdvanced = function () { + vm.showAdvanced = !vm.showAdvanced; + vm.independentIssuer = !vm.independentIssuer; + }; + + vm.notification = true; + + vm._setSubject = function (subject) { + vm.currentSubject = vm.newSubject; + subject = subject || vm.newSubject; + var issuer = subject.replace(/.*@/, ''); + if (vm.independentIssuer) { + return $timeout(function () { return; }, 0); + } + return Oauth3.discover(issuer, { client_uri: Oauth3.clientUri(location) }).then(function (deets) { + return vm._setIssuer(issuer); + }, function () { + // ignore error + }); + }; + + vm.setSubject = function (subject) { + $timeout.cancel(vm.timers.subject); + vm.timers.subject = $timeout(function () { + vm._setSubject(subject); + }, 300); + }; + + vm._setIssuer = function (url) { + vm.spinner = true; + url = (url || vm.newIssuer).replace(/.*@/, ''); + if (!url) { + url = vm.defaultIssuer; + } + + return Oauth3.discover(url, { client_uri: Oauth3.clientUri(location) }).then(function (deets) { + vm.currentIssuer = url; + vm.issuerName = url; + + return vm.newOauth3.setIdentityProvider(url).then(function (deets) { + vm.newOauth3.setResourceProvider(url); + vm.spinner = false; + // TODO add icon and name to directives + }); + }, function () { + console.log("oauth3 discover timeout: No dice, no change for '" + url + "'"); + vm.spinner = false; + }); + }; + + vm.setIssuer = function (url) { + $timeout.cancel(vm.timers.issuer); + vm.timers.issuer = $timeout(function () { + vm._setIssuer(url); + }, 300); + }; + + vm.setAudience = function (url) { + url = url || vm.audienceUrl; + vm.audienceName = url; + vm.newOauth3.setResourceProvider(url); + }; + + vm.selectSession = function (session) { + vm.xauth = true; + vm.session = session; + return Auth.select(session).then(function (oauth3) { + vm.xauth = false; + }); + }; + + vm.instaauth = function () { + return vm._setSubject().then(function () { + return vm._setIssuer().then(function () { + return vm.auth(); + }); + }); + }; + + vm.auth = function () { + var subject = vm.currentSubject; + var issuer = vm.issuerName; + return vm.newOauth3.authenticate({ + subject: subject + , scope: [ 'domains@oauth3.org', 'domains', 'dns@oauth3.org', 'dns', 'www@daplie.com' ] + }).then(function (session) { + session.subject = subject; + session.issuer = issuer; + Auth.add(session); + if ($rootScope.redirectedURL === '/splash-page') { + $location.path('/home'); + } else { + $location.path('/' + $rootScope.redirectedURL); + } + }, function (err) { + console.error('auth error'); + console.error(err); + }); + }; + + vm.newIssuer = vm.defaultIssuer; + vm.setIssuer(vm.defaultIssuer); + + vm.getSession = function() { + return Auth.select(Auth.session); + }; + + vm.initListLoggedInProfiles = function () { + vm.activeProfiles = Auth.getActiveSessions(); + }; + + vm.signIn = function () { + vm.auth(); + }; + + vm.masterLogOut = function () { + localStorage.clear(); + $location.path('/splash-page'); + }; + + vm.signOut = function () { + vm.getSession().then(function(){ + // TODO the sign-out url for each account should be fixed. + return Auth.signOut().then(function () { + if (Auth.sessions.length === 0) { + $location.path('/splash-page'); + return; + } + window.alert("You are still logged in with other accounts."); + }); + }); + }; + + vm.Profile = {}; + vm.Profile.update = function (a) { + console.log('Click click click!!!'); + var pkg = Auth.oauth3.pkg('issuer@oauth3.org'); + + return pkg.update({ + displayName: a.displayName + , avatarUrl: a.avatarUrl + , firstName: a.firstName + , lastName: a.lastName + //, names: a.names + , primaryEmail: a.primaryEmail // TODO make a combobox of available emails (and require confirm before making primary) + , primaryPhone: a.primaryPhone + }).then(function (result) { + window.alert(JSON.stringify(result)); + // TODO use iframe to initiate download? + vm.account = result.data; + }); + }; + vm.Profile.get = function () { + var pkg = Auth.oauth3.pkg('issuer@oauth3.org'); + + return pkg.get().then(function (result) { + console.log(result.data); + vm.account = result.data; + vm.profile = result.data; + }); + }; + + vm.Profile.get(); + +}]); diff --git a/js/issuer@oauth3.org.js b/js/issuer@oauth3.org.js new file mode 100644 index 0000000..ab0e06c --- /dev/null +++ b/js/issuer@oauth3.org.js @@ -0,0 +1,78 @@ +(function (exports) { +'use strict'; + +var OAUTH3 = exports.OAUTH3 = exports.OAUTH3 || require('./oauth3.core.js').OAUTH3; + +OAUTH3._pkgs['issuer@oauth3.org'] = { + update: function (opts) { + var providerUri = opts.audience; + var session = opts.session; + + return OAUTH3.request({ + method: 'POST' + , url: OAUTH3.url.normalize(providerUri) + + '/api/issuer@oauth3.org/acl/profile/' + , session: session + , data: { + displayName: opts.displayName + , avatarUrl: opts.avatarUrl + , firstName: opts.firstName + , lastName: opts.lastName + , primaryEmail: opts.primaryEmail + , primaryPhone: opts.primaryPhone + } + }).then(function (result) { + return result; + }); + } +, get: function (opts) { + var providerUri = opts.audience; + var session = opts.session; + + return OAUTH3.request({ + method: 'GET' + , url: OAUTH3.url.normalize(providerUri) + + '/api/issuer@oauth3.org/acl/profile/' + , session: session + }).then(function (result) { + return result; + }); + } +, requestContact: function (opts) { + var providerUri = opts.audience; + var session = opts.session; + + return OAUTH3.request({ + method: 'POST' + , url: OAUTH3.url.normalize(providerUri) + + '/api/issuer@oauth3.org/acl/contact_nodes/' + , session: session + , data: { + type: opts.type + , node: opts.node + } + }).then(function (result) { + return result; + }); + } +, verifyContact: function (opts) { + var providerUri = opts.audience; + var session = opts.session; + + return OAUTH3.request({ + method: 'POST' + , url: OAUTH3.url.normalize(providerUri) + + '/api/issuer@oauth3.org/acl/contact_nodes/' + , session: session + , data: { + type: opts.type + , node: opts.node + , challenge: opts.challenge + } + }).then(function (result) { + return result; + }); + } +}; + +}('undefined' !== typeof exports ? exports : window)); diff --git a/templates/account-settings.html b/templates/account-settings.html index 75e88b9..e0e13ee 100644 --- a/templates/account-settings.html +++ b/templates/account-settings.html @@ -1,4 +1,4 @@ -

Account Settings

+

Profile Settings

@@ -9,22 +9,34 @@
+
+ +
+ +
+
- +
- +
- + +
+
+
+ +
+
diff --git a/templates/website.html b/templates/website.html index 6abe41b..344b370 100644 --- a/templates/website.html +++ b/templates/website.html @@ -52,7 +52,7 @@
-->
-
+
@@ -89,22 +89,27 @@ - + + - +
example.com + + example.com + (pending) Download - Sites > blogs > blog.jane.smith.net
- / - friend@email.com - pending - (rwx) - -
+
+ / + friend@email.com + pending + (rwx) + +
+
From efbe637e1bc6852cff6c68cce0ff43a227bb78c9 Mon Sep 17 00:00:00 2001 From: aj Date: Fri, 29 Sep 2017 00:04:04 +0000 Subject: [PATCH 2/2] use path and confirm for deleting --- js/controllers/website-controller.js | 59 ++++++++++++++++------------ templates/website.html | 2 +- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/js/controllers/website-controller.js b/js/controllers/website-controller.js index f6b77f2..29fe4bb 100644 --- a/js/controllers/website-controller.js +++ b/js/controllers/website-controller.js @@ -1,3 +1,7 @@ +(function () { +'use strict'; + +var app = window.app; // // Angular file upload hack // @@ -9,6 +13,7 @@ function analyzeFile(file, vm) { return vm; } +/* function handleFiles(ev) { var selector = 'js-file-upload'; var $scope; @@ -29,30 +34,23 @@ function handleFiles(ev) { console.log(vm.currentFiles); } window.document.body.addEventListener('change', handleFiles); - -app.directive('daplieFileChange', function () { - return { - restrict: 'A', - require:"ngModel", - link: function (scope, element, attrs, ngModel) { - element.bind('change', function (event) { - var files = event.target.files; - ngModel.$setViewValue(files[0]); - scope.$eval(attrs.daplieFileChange); - }); - } - }; -}); +*/ app.controller('websiteCtrl', [ '$scope', '$q', 'Auth', 'azp@oauth3.org', '$timeout' , function ($scope, $q, Auth, Oauth3, $timeout) { var vm = this; + var angular = window.angular; vm.domains = []; //vm.unzipPath = '/'; vm.uploadPath = '/'; + // already validated + function domainIsVerified(r) { + return r.verifiedAt || r.mode; + } + Auth.api = function (apiname, opts) { var els = []; @@ -161,13 +159,13 @@ app.controller('websiteCtrl', [ vm._uploadFileVm = function (pkg, opts) { return vm._uploadFile(pkg, { - domain: vm.currentHost - , tld: vm.domain.tld - , sld: vm.domain.sld - , sub: vm.domain.sub - , newFile: vm.currentFiles[0] - , uploadPath: vm.uploadPath - , progress: vm + domain: opts.currentHost + , tld: opts.domain.tld + , sld: opts.domain.sld + , sub: opts.domain.sub + , newFile: opts.newFile + , uploadPath: opts.uploadPath + , progress: opts }); }; vm._uploadFile = function (pkg, opts) { @@ -207,6 +205,7 @@ app.controller('websiteCtrl', [ var sld; var tld; + /* //vm.unlock('webpreneur'); if (!vm.currentFiles || !vm.currentFiles.length) { window.alert('No files chosen.'); @@ -216,6 +215,11 @@ app.controller('websiteCtrl', [ window.alert('Too many files chosen.'); return; } + */ + if (!vm.newFile) { + window.alert('No file chosen.'); + return; + } if (!vm.currentHost) { window.alert('No hostname chosen.'); return; @@ -238,9 +242,8 @@ app.controller('websiteCtrl', [ sub = parts.join('.'); } - // already validated if (vm.sites.some(function (r) { - return -1 !== ('.' + vm.currentHost).indexOf(('.' + r.domain)); + return (-1 !== ('.' + vm.currentHost).indexOf(('.' + r.domain))) && domainIsVerified(r); })) { vm._uploadFileVm(pkg, vm); return; @@ -319,7 +322,7 @@ app.controller('websiteCtrl', [ window.open(result.data.url); }); }; - vm.Sites.remove = function (r) { + vm.Sites.remove = function (r, opts) { if (!window.confirm("Delete files for this site?")) { return; } @@ -331,7 +334,8 @@ app.controller('websiteCtrl', [ , tld: r.tld , sld: r.sld //, sub: vm.record.sub - //, path: vm.uploadPath + , path: opts.path || r.path + , confirm: opts.confirm || r.confirm }).then(function (result) { window.alert(JSON.stringify(result)); }); @@ -445,6 +449,9 @@ app.controller('websiteCtrl', [ }); }); })).then(function () { + sites.forEach(function (site) { + site.pending = !domainIsVerified(site); + }); console.log('[listSites] sites:'); console.log(sites); vm.sites = sites; @@ -483,3 +490,5 @@ app.controller('websiteCtrl', [ return matches; }; }]); + +}()); diff --git a/templates/website.html b/templates/website.html index 344b370..db20386 100644 --- a/templates/website.html +++ b/templates/website.html @@ -94,7 +94,7 @@ (pending) Download - +