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) {
|
||||
$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 });
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}]);
|
||||
}());
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue