fixing logging in and redirects with token
This commit is contained in:
		
							parent
							
								
									9368a25fd2
								
							
						
					
					
						commit
						8f987882d2
					
				
							
								
								
									
										34
									
								
								js/app.js
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								js/app.js
									
									
									
									
									
								
							| @ -155,40 +155,26 @@ app.config([ | |||||||
| }]); | }]); | ||||||
| 
 | 
 | ||||||
| app.run(['$rootScope', '$state', 'Auth', '$location', function($rootScope, $state, Auth, $location) { | app.run(['$rootScope', '$state', 'Auth', '$location', function($rootScope, $state, Auth, $location) { | ||||||
|   $rootScope.urlArray = []; |  | ||||||
|   $rootScope.urlCrumbs = []; |   $rootScope.urlCrumbs = []; | ||||||
|   $rootScope.urlInfo = { |  | ||||||
|     url: $location.$$url, |  | ||||||
|     path: $location.$$path, |  | ||||||
|     params: $location.$$search |  | ||||||
|   }; |  | ||||||
|   debugger; |  | ||||||
|   $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { |   $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { | ||||||
|     var requiresLogin = toState.data.requiresLogin; |     var requiresLogin = toState.data.requiresLogin; | ||||||
|     toState.data.session = $location.search(); |     toState.data.session = $location.search(); | ||||||
|     $rootScope.redirectedURL = toState.url; |  | ||||||
|     var query = $location.search(); |     var query = $location.search(); | ||||||
|     $rootScope.urlArray.push($rootScope.redirectedURL); |     var Crumbs = new Object(); | ||||||
|     $rootScope.urlCrumbs.push($rootScope.urlInfo); |     Crumbs = { | ||||||
|     debugger; |       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()) { |     if (requiresLogin && !Auth.isLoggedIn()) { | ||||||
|       event.preventDefault(); |  | ||||||
|       if (!angular.equals(toState.data.session, {})) { |       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 }); |         $state.go('splash-page', { 'toState': toState.name }); | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
| 
 |  | ||||||
|   }); |   }); | ||||||
| }]); | }]); | ||||||
| }()); | }()); | ||||||
|  | |||||||
| @ -105,12 +105,15 @@ app.controller('loginCtrl', [ | |||||||
|       session.subject = subject; |       session.subject = subject; | ||||||
|       session.issuer = issuer; |       session.issuer = issuer; | ||||||
|       Auth.add(session); |       Auth.add(session); | ||||||
|       if ($rootScope.redirectedURL === '/splash-page') { |       if (Auth.sessions.length === 1) { | ||||||
|         debugger; |         if ($rootScope.urlCrumbs[0].path === '/splash-page') { | ||||||
|         $location.path('/home'); |           $location.path('/home'); | ||||||
|  |         } else { | ||||||
|  |           window.location.replace($rootScope.urlCrumbs[0].absUrl); | ||||||
|  |         } | ||||||
|       } else { |       } else { | ||||||
|         debugger; |         location.reload(); | ||||||
|         $location.path('/' + $rootScope.urlInfo.url); |         // window.location.replace($rootScope.urlCrumbs[$rootScope.urlCrumbs.length -1].absUrl);
 | ||||||
|       } |       } | ||||||
|     }, function (err) { |     }, function (err) { | ||||||
|       console.error('auth error'); |       console.error('auth error'); | ||||||
|  | |||||||
| @ -190,13 +190,11 @@ app.controller('websiteCtrl', [ | |||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   vm.shareInit = function () { |   vm.shareInit = function () { | ||||||
|     if ($rootScope.urlInfo.params.token !== undefined) { |     if ($rootScope.urlCrumbs[$rootScope.urlCrumbs.length -1].params.token !== undefined) { | ||||||
|       console.log('FISH STICKS', $rootScope.urlInfo); |       vm.Shares.inviteToken = $rootScope.urlCrumbs[$rootScope.urlCrumbs.length -1].params.token; | ||||||
|       vm.Shares.inviteToken = $rootScope.urlInfo.params.token; |  | ||||||
|       var result = { data: { info: true } }; |       var result = { data: { info: true } }; | ||||||
|       var msg = "You have a new share."; |       var msg = "You have a new share."; | ||||||
|       vm.buildNotification(result, msg); |       vm.buildNotification(result, msg); | ||||||
|       // debugger;
 |  | ||||||
|     } |     } | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
| @ -619,9 +617,15 @@ app.controller('websiteCtrl', [ | |||||||
|     return pkg.acceptInvite({ |     return pkg.acceptInvite({ | ||||||
|       token: vm.Shares.inviteToken |       token: vm.Shares.inviteToken | ||||||
|     }).then(function (result) { |     }).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.listSites(); | ||||||
|     }); |     }); | ||||||
|  | 
 | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   vm.Shares.list = function (r) { |   vm.Shares.list = function (r) { | ||||||
|  | |||||||
| @ -22,8 +22,6 @@ app.factory('Auth', [ | |||||||
|       return Auth.sessions || false; |       return Auth.sessions || false; | ||||||
|     } |     } | ||||||
|   , add: function (session) { |   , add: function (session) { | ||||||
|       console.log($rootScope); |  | ||||||
|       debugger; |  | ||||||
|       var obj = JSON.parse(localStorage.getItem(dapSessions) || 'null') || {}; |       var obj = JSON.parse(localStorage.getItem(dapSessions) || 'null') || {}; | ||||||
|       var dapName = 'dap-' + session.subject + '|' + session.issuer; |       var dapName = 'dap-' + session.subject + '|' + session.issuer; | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user