From 8f987882d24ffc20c537ccd622ee7969ee6781dc Mon Sep 17 00:00:00 2001 From: Jon Lambson Date: Tue, 31 Oct 2017 15:55:05 -0600 Subject: [PATCH] fixing logging in and redirects with token --- js/app.js | 34 ++++++++-------------------- js/controllers/login-controller.js | 13 +++++++---- js/controllers/website-controller.js | 14 ++++++++---- js/services/auth-service.js | 2 -- 4 files changed, 27 insertions(+), 36 deletions(-) diff --git a/js/app.js b/js/app.js index c5151cb..0a56fd6 100644 --- a/js/app.js +++ b/js/app.js @@ -155,40 +155,26 @@ app.config([ }]); app.run(['$rootScope', '$state', 'Auth', '$location', function($rootScope, $state, Auth, $location) { - $rootScope.urlArray = []; $rootScope.urlCrumbs = []; - $rootScope.urlInfo = { - url: $location.$$url, - path: $location.$$path, - params: $location.$$search - }; - debugger; $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { var requiresLogin = toState.data.requiresLogin; toState.data.session = $location.search(); - $rootScope.redirectedURL = toState.url; var query = $location.search(); - $rootScope.urlArray.push($rootScope.redirectedURL); - $rootScope.urlCrumbs.push($rootScope.urlInfo); - debugger; + var Crumbs = new Object(); + Crumbs = { + absUrl: $location.$$absUrl, + url: $location.$$url, + path: $location.$$path, + params: $location.$$search, + toPath: toState.url, + fromPath: fromState.url + }; + $rootScope.urlCrumbs.push(Crumbs); if (requiresLogin && !Auth.isLoggedIn()) { - event.preventDefault(); if (!angular.equals(toState.data.session, {})) { - debugger; - if (toState.data.session.refresh !== undefined) { - toState.data.session.token = OAUTH3.jwt.decode(query.access_token); - toState.data.session.refresh = OAUTH3.jwt.decode(query.refresh_token); - Auth.add(query); - $state.go('app.' + $rootScope.redirectedURL); - } else { - $state.go('splash-page', { 'toState': toState.name }); - debugger; - } - } else { $state.go('splash-page', { 'toState': toState.name }); } } - }); }]); }()); diff --git a/js/controllers/login-controller.js b/js/controllers/login-controller.js index 6289cc1..8a6a4a8 100644 --- a/js/controllers/login-controller.js +++ b/js/controllers/login-controller.js @@ -105,12 +105,15 @@ app.controller('loginCtrl', [ session.subject = subject; session.issuer = issuer; Auth.add(session); - if ($rootScope.redirectedURL === '/splash-page') { - debugger; - $location.path('/home'); + if (Auth.sessions.length === 1) { + if ($rootScope.urlCrumbs[0].path === '/splash-page') { + $location.path('/home'); + } else { + window.location.replace($rootScope.urlCrumbs[0].absUrl); + } } else { - debugger; - $location.path('/' + $rootScope.urlInfo.url); + location.reload(); + // window.location.replace($rootScope.urlCrumbs[$rootScope.urlCrumbs.length -1].absUrl); } }, function (err) { console.error('auth error'); diff --git a/js/controllers/website-controller.js b/js/controllers/website-controller.js index 3ccc187..1d5456d 100644 --- a/js/controllers/website-controller.js +++ b/js/controllers/website-controller.js @@ -190,13 +190,11 @@ app.controller('websiteCtrl', [ }; vm.shareInit = function () { - if ($rootScope.urlInfo.params.token !== undefined) { - console.log('FISH STICKS', $rootScope.urlInfo); - vm.Shares.inviteToken = $rootScope.urlInfo.params.token; + if ($rootScope.urlCrumbs[$rootScope.urlCrumbs.length -1].params.token !== undefined) { + vm.Shares.inviteToken = $rootScope.urlCrumbs[$rootScope.urlCrumbs.length -1].params.token; var result = { data: { info: true } }; var msg = "You have a new share."; vm.buildNotification(result, msg); - // debugger; } }; @@ -619,9 +617,15 @@ app.controller('websiteCtrl', [ return pkg.acceptInvite({ token: vm.Shares.inviteToken }).then(function (result) { - window.alert(JSON.stringify(result)); + var person = result.data.comment; + var path = result.data.path; + var shareMode = result.data.mode; + var domain = result.data.domain; + var msg = 'You accepted a share ' + "'" + domain + "'" + ' from ' + person + '. Take a look at your vefrified websites below.'; + vm.buildNotification(result, msg); vm.listSites(); }); + }; vm.Shares.list = function (r) { diff --git a/js/services/auth-service.js b/js/services/auth-service.js index 095e067..7331351 100644 --- a/js/services/auth-service.js +++ b/js/services/auth-service.js @@ -22,8 +22,6 @@ app.factory('Auth', [ return Auth.sessions || false; } , add: function (session) { - console.log($rootScope); - debugger; var obj = JSON.parse(localStorage.getItem(dapSessions) || 'null') || {}; var dapName = 'dap-' + session.subject + '|' + session.issuer;