mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 01:17:37 -02:30
Force user to login before opening web sockets
Rearranged the series of events so that the socket handshake happens after the user logs in.
This commit is contained in:
@@ -509,6 +509,67 @@ angular.module('Tower', [
|
|||||||
|
|
||||||
$rootScope.browser = detectBrowser();
|
$rootScope.browser = detectBrowser();
|
||||||
|
|
||||||
|
if ($rootScope.removeOpenSocket) {
|
||||||
|
$rootScope.removeOpenSocket();
|
||||||
|
}
|
||||||
|
$rootScope.removeOpenSocket = $rootScope.$on('OpenSocket', function() {
|
||||||
|
html = "<a href=\"\" ng-click=\"socketHelp()\" aw-pop-over=\"{{ socketTip }}\" aw-pop-over-watch=\"socketTip\" data-placement=\"bottom\" data-trigger=\"hover\" " +
|
||||||
|
"data-popover-title=\"Live Events\" data-container=\"body\" style=\"font-size: 10px;\"><i class=\"fa icon-socket-{{ socketStatus }}\"></i></a>";
|
||||||
|
e = angular.element(document.getElementById('socket-beacon-div'));
|
||||||
|
e.empty().append(html);
|
||||||
|
$compile(e)($rootScope);
|
||||||
|
|
||||||
|
e = angular.element(document.getElementById('socket-beacon-li'));
|
||||||
|
e.empty().append(html);
|
||||||
|
$compile(e)($rootScope);
|
||||||
|
|
||||||
|
// Listen for job changes and issue callbacks to initiate
|
||||||
|
// DOM updates
|
||||||
|
function openSocket() {
|
||||||
|
sock = Socket({ scope: $rootScope, endpoint: "jobs" });
|
||||||
|
sock.init();
|
||||||
|
sock.on("status_changed", function(data) {
|
||||||
|
$log.debug('Job ' + data.unified_job_id + ' status changed to ' + data.status);
|
||||||
|
$rootScope.$emit('JobStatusChange', data);
|
||||||
|
});
|
||||||
|
sock.on("summary_complete", function(data) {
|
||||||
|
$log.debug('Job summary_complete ' + data.unified_job_id);
|
||||||
|
$rootScope.$emit('JobSummaryComplete', data);
|
||||||
|
});
|
||||||
|
sock.on("schedule_change", function(data) {
|
||||||
|
$log.debug('schedule changed to ' + data.status);
|
||||||
|
$rootScope.$emit('ScheduleChange', data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
openSocket();
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
$rootScope.$apply(function() {
|
||||||
|
sock.checkStatus();
|
||||||
|
$log.debug('socket status: ' + $rootScope.socketStatus);
|
||||||
|
});
|
||||||
|
},2000);
|
||||||
|
|
||||||
|
// monitor socket status
|
||||||
|
checkCount = 0;
|
||||||
|
setInterval(function() {
|
||||||
|
if (sock.checkStatus() === 'error' || checkCount > 5) {
|
||||||
|
// there's an error or we're stuck in a 'connecting' state. attempt to reconnect
|
||||||
|
$log.debug('socket status: ' + sock.checkStatus());
|
||||||
|
$log.debug('attempting new socket connection');
|
||||||
|
sock = null;
|
||||||
|
openSocket();
|
||||||
|
checkCount = 0;
|
||||||
|
}
|
||||||
|
else if (sock.checkStatus() === 'connecting') {
|
||||||
|
checkCount++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
checkCount = 0;
|
||||||
|
}
|
||||||
|
}, 5000);
|
||||||
|
});
|
||||||
|
|
||||||
$rootScope.$on("$routeChangeStart", function (event, next) {
|
$rootScope.$on("$routeChangeStart", function (event, next) {
|
||||||
// Before navigating away from current tab, make sure the primary view is visible
|
// Before navigating away from current tab, make sure the primary view is visible
|
||||||
if ($('#stream-container').is(':visible')) {
|
if ($('#stream-container').is(':visible')) {
|
||||||
@@ -605,63 +666,71 @@ angular.module('Tower', [
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
html = "<a href=\"\" ng-click=\"socketHelp()\" aw-pop-over=\"{{ socketTip }}\" aw-pop-over-watch=\"socketTip\" data-placement=\"bottom\" data-trigger=\"hover\" " +
|
// html = "<a href=\"\" ng-click=\"socketHelp()\" aw-pop-over=\"{{ socketTip }}\" aw-pop-over-watch=\"socketTip\" data-placement=\"bottom\" data-trigger=\"hover\" " +
|
||||||
"data-popover-title=\"Live Events\" data-container=\"body\" style=\"font-size: 10px;\"><i class=\"fa icon-socket-{{ socketStatus }}\"></i></a>";
|
// "data-popover-title=\"Live Events\" data-container=\"body\" style=\"font-size: 10px;\"><i class=\"fa icon-socket-{{ socketStatus }}\"></i></a>";
|
||||||
e = angular.element(document.getElementById('socket-beacon-div'));
|
// e = angular.element(document.getElementById('socket-beacon-div'));
|
||||||
e.empty().append(html);
|
// e.empty().append(html);
|
||||||
$compile(e)($rootScope);
|
// $compile(e)($rootScope);
|
||||||
|
|
||||||
e = angular.element(document.getElementById('socket-beacon-li'));
|
// e = angular.element(document.getElementById('socket-beacon-li'));
|
||||||
e.empty().append(html);
|
// e.empty().append(html);
|
||||||
$compile(e)($rootScope);
|
// $compile(e)($rootScope);
|
||||||
|
|
||||||
// Listen for job changes and issue callbacks to initiate
|
// // Listen for job changes and issue callbacks to initiate
|
||||||
// DOM updates
|
// // DOM updates
|
||||||
function openSocket() {
|
// function openSocket() {
|
||||||
sock = Socket({ scope: $rootScope, endpoint: "jobs" });
|
// sock = Socket({ scope: $rootScope, endpoint: "jobs" });
|
||||||
sock.init();
|
// sock.init();
|
||||||
sock.on("status_changed", function(data) {
|
// sock.on("status_changed", function(data) {
|
||||||
$log.debug('Job ' + data.unified_job_id + ' status changed to ' + data.status);
|
// $log.debug('Job ' + data.unified_job_id + ' status changed to ' + data.status);
|
||||||
$rootScope.$emit('JobStatusChange', data);
|
// $rootScope.$emit('JobStatusChange', data);
|
||||||
});
|
// });
|
||||||
sock.on("summary_complete", function(data) {
|
// sock.on("summary_complete", function(data) {
|
||||||
$log.debug('Job summary_complete ' + data.unified_job_id);
|
// $log.debug('Job summary_complete ' + data.unified_job_id);
|
||||||
$rootScope.$emit('JobSummaryComplete', data);
|
// $rootScope.$emit('JobSummaryComplete', data);
|
||||||
});
|
// });
|
||||||
sock.on("schedule_change", function(data) {
|
// sock.on("schedule_change", function(data) {
|
||||||
$log.debug('schedule changed to ' + data.status);
|
// $log.debug('schedule changed to ' + data.status);
|
||||||
$rootScope.$emit('ScheduleChange', data);
|
// $rootScope.$emit('ScheduleChange', data);
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
openSocket();
|
// if ($rootScope.removeOpenSocket) {
|
||||||
|
// $rootScope.removeOpenSocket();
|
||||||
|
// }
|
||||||
|
// $rootScope.removeOpenSocket = $rootScope.$on('OpenSocket', function() {
|
||||||
|
|
||||||
setTimeout(function() {
|
// openSocket();
|
||||||
$rootScope.$apply(function() {
|
|
||||||
sock.checkStatus();
|
// setTimeout(function() {
|
||||||
$log.debug('socket status: ' + $rootScope.socketStatus);
|
// $rootScope.$apply(function() {
|
||||||
});
|
// sock.checkStatus();
|
||||||
},2000);
|
// $log.debug('socket status: ' + $rootScope.socketStatus);
|
||||||
|
// });
|
||||||
|
// },2000);
|
||||||
|
|
||||||
|
// // monitor socket status
|
||||||
|
// checkCount = 0;
|
||||||
|
// setInterval(function() {
|
||||||
|
// if (sock.checkStatus() === 'error' || checkCount > 5) {
|
||||||
|
// // there's an error or we're stuck in a 'connecting' state. attempt to reconnect
|
||||||
|
// $log.debug('socket status: ' + sock.checkStatus());
|
||||||
|
// $log.debug('attempting new socket connection');
|
||||||
|
// sock = null;
|
||||||
|
// openSocket();
|
||||||
|
// checkCount = 0;
|
||||||
|
// }
|
||||||
|
// else if (sock.checkStatus() === 'connecting') {
|
||||||
|
// checkCount++;
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// checkCount = 0;
|
||||||
|
// }
|
||||||
|
// }, 5000);
|
||||||
|
// });
|
||||||
|
|
||||||
|
}); // end of 'ConfigReady'
|
||||||
|
|
||||||
// monitor socket status
|
|
||||||
checkCount = 0;
|
|
||||||
setInterval(function() {
|
|
||||||
if (sock.checkStatus() === 'error' || checkCount > 5) {
|
|
||||||
// there's an error or we're stuck in a 'connecting' state. attempt to reconnect
|
|
||||||
$log.debug('socket status: ' + sock.checkStatus());
|
|
||||||
$log.debug('attempting new socket connection');
|
|
||||||
sock = null;
|
|
||||||
openSocket();
|
|
||||||
checkCount = 0;
|
|
||||||
}
|
|
||||||
else if (sock.checkStatus() === 'connecting') {
|
|
||||||
checkCount++;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
checkCount = 0;
|
|
||||||
}
|
|
||||||
}, 5000);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!$AnsibleConfig) {
|
if (!$AnsibleConfig) {
|
||||||
// there may be time lag when loading the config file, so temporarily use what's in local storage
|
// there may be time lag when loading the config file, so temporarily use what's in local storage
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ angular.module('CustomInventoryListDefinition', [])
|
|||||||
iterator: 'custom_inventory',
|
iterator: 'custom_inventory',
|
||||||
selectTitle: 'Add custom inventory',
|
selectTitle: 'Add custom inventory',
|
||||||
editTitle: 'Custom Inventories',
|
editTitle: 'Custom Inventories',
|
||||||
selectInstructions: "<p>Select existing credentials by clicking each credential or checking the related checkbox. When " +
|
// selectInstructions: "<p>Select existing credentials by clicking each credential or checking the related checkbox. When " +
|
||||||
"finished, click the blue <em>Select</em> button, located bottom right.</p> <p>Create a brand new credential by clicking " +
|
// "finished, click the blue <em>Select</em> button, located bottom right.</p> <p>Create a brand new credential by clicking " +
|
||||||
"the <i class=\"fa fa-plus\"></i> button.</p><div class=\"popover-footer\"><span class=\"key\">esc</span> or click to close</div>",
|
// "the <i class=\"fa fa-plus\"></i> button.</p><div class=\"popover-footer\"><span class=\"key\">esc</span> or click to close</div>",
|
||||||
index: false,
|
index: false,
|
||||||
hover: true,
|
hover: false,
|
||||||
|
|
||||||
fields: {
|
fields: {
|
||||||
name: {
|
name: {
|
||||||
|
|||||||
@@ -136,10 +136,12 @@ angular.module('AuthService', ['ngCookies', 'Utilities'])
|
|||||||
// store the response values in $rootScope so we can get to them later
|
// store the response values in $rootScope so we can get to them later
|
||||||
$rootScope.current_user = response.results[0];
|
$rootScope.current_user = response.results[0];
|
||||||
$cookieStore.put('current_user', response.results[0]); //keep in session cookie in the event of browser refresh
|
$cookieStore.put('current_user', response.results[0]); //keep in session cookie in the event of browser refresh
|
||||||
|
$rootScope.$emit('OpenSocket');
|
||||||
},
|
},
|
||||||
|
|
||||||
restoreUserInfo: function () {
|
restoreUserInfo: function () {
|
||||||
$rootScope.current_user = $cookieStore.get('current_user');
|
$rootScope.current_user = $cookieStore.get('current_user');
|
||||||
|
$rootScope.$emit('OpenSocket');
|
||||||
},
|
},
|
||||||
|
|
||||||
getUserInfo: function (key) {
|
getUserInfo: function (key) {
|
||||||
|
|||||||
Reference in New Issue
Block a user