1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Merge pull request #2440 from jaredevantabor/session

Adding an extra session check for when a user closes Tower
This commit is contained in:
Jared Tabor 2016-06-16 12:28:10 -07:00 committed by GitHub
commit bdcb6e5c20
8 changed files with 42 additions and 37 deletions

View File

@ -870,11 +870,17 @@ var tower = angular.module('Tower', [
if (!Authorization.getToken() || !Authorization.isUserLoggedIn()) {
// User not authenticated, redirect to login page
$rootScope.sessionExpired = false;
$cookieStore.put('sessionExpired', false);
$rootScope.configReady = true;
$location.path('/login');
} else {
var lastUser = $cookieStore.get('current_user'),
timestammp = Store('sessionTime');
if(lastUser && lastUser.id && timestammp && timestammp[lastUser.id]){
var stime = timestammp[lastUser.id].time,
now = new Date().getTime();
if ((stime - now) <= 0) {
$location.path('/login');
}
}
// If browser refresh, set the user_is_superuser value
$rootScope.user_is_superuser = Authorization.getUserInfo('is_superuser');
// state the user refreshes we want to open the socket, except if the user is on the login page, which should happen after the user logs in (see the AuthService module for that call to OpenSocket)

View File

@ -1,4 +1,4 @@
<div id="bread_crumb" class="BreadCrumb" ng-class="{'is-loggedOut' : !$root.current_user.username}">
<div id="bread_crumb" class="BreadCrumb" ng-class="{'is-loggedOut' : !current_user || !current_user.username}">
<div ng-hide="licenseMissing" ncy-breadcrumb></div>
<div class="BreadCrumb-menuLink"
id="bread_crumb_activity_stream"

View File

@ -1,3 +1,3 @@
<footer class='Footer'>
<div class="Footer-copyright" ng-class="{'is-loggedOut' : !$root.current_user.username}">Copyright &copy 2016 <a class="Footer-link" href="http://www.redhat.com" target="_blank">Red Hat</a>, Inc.</div>
<div class="Footer-copyright" ng-class="{'is-loggedOut' : !current_user || !current_user.username}">Copyright &copy 2016 <a class="Footer-link" href="http://www.redhat.com" target="_blank">Red Hat</a>, Inc.</div>
</footer>

View File

@ -66,8 +66,10 @@ export default
var x,
ConfigService = $injector.get('ConfigService'),
scope = angular.element(document.getElementById('main-view')).scope();
scope.$destroy();
//$rootScope.$destroy();
if(scope){
scope.$destroy();
}
if($cookieStore.get('lastPath')==='/portal'){
$cookieStore.put( 'lastPath', '/portal');
@ -101,7 +103,7 @@ export default
$rootScope.current_user = {};
$rootScope.license_tested = undefined;
$rootScope.userLoggedIn = false;
// $rootScope.sessionExpired = false;
$rootScope.sessionExpired = false;
$rootScope.licenseMissing = true;
$rootScope.token = null;
$rootScope.token_expires = null;

View File

@ -10,12 +10,16 @@ export default {
name: 'signIn',
route: '/login',
templateUrl: templateUrl('login/loginBackDrop'),
controller: ['$rootScope', 'Authorization', function($rootScope, Authorization) {
if (Authorization.isUserLoggedIn()) {
Authorization.logout();
}
$(".LoginModal-dialog").remove();
}],
resolve: {
obj: ['$rootScope', 'Authorization',
function($rootScope, Authorization) {
$rootScope.configReady = true;
if (Authorization.isUserLoggedIn()) {
Authorization.logout();
}
$(".LoginModal-dialog").remove();
}]
},
ncyBreadcrumb: {
skip: true
}

View File

@ -61,10 +61,8 @@ export default ['$log', '$cookieStore', '$compile', '$window', '$rootScope',
function ($log, $cookieStore, $compile, $window, $rootScope, $location,
Authorization, ToggleClass, Alert, Wait, Timer, Empty, ClearScope,
scope, pendoService, ConfigService, CheckLicense, FeaturesService) {
var lastPath, lastUser, sessionExpired, loginAgain;
$rootScope.configReady = true;
loginAgain = function() {
setTimeout(function() {
$location.path('/logout');
@ -75,6 +73,7 @@ export default ['$log', '$cookieStore', '$compile', '$window', '$rootScope',
scope.login_username = '';
scope.login_password = '';
lastPath = function () {
return (Empty($rootScope.lastPath)) ? $cookieStore.get('lastPath') : $rootScope.lastPath;
};
@ -104,12 +103,6 @@ export default ['$log', '$cookieStore', '$compile', '$window', '$rootScope',
scope.customLoginInfoPresent = (scope.customLoginInfo) ? true : false;
});
// Reset the login form
//scope.loginForm.login_username.$setPristine();
//scope.loginForm.login_password.$setPristine();
//$rootScope.userLoggedIn = false; //hide the logout link. if you got here, you're logged out.
//$cookieStore.put('userLoggedIn', false); //gets set back to true by Authorization.setToken().
if (scope.removeAuthorizationGetLicense) {
scope.removeAuthorizationGetLicense();
}

View File

@ -1,9 +1,9 @@
<div id="login-modal" class="LoginModal">
<div class="LoginModal-backDrop"
ng-class="{'is-loggedOut' : !$root || !$root.current_user.username}"></div>
ng-class="{'is-loggedOut' : !current_user || !current_user.username}"></div>
<div class="LoginModal-dialog">
<div class="LoginModal-content"
ng-class="{'is-loggedOut' : !$root || !$root.current_user.username}">
ng-class="{'is-loggedOut' : !current_user || !current_user.username}">
<div class="LoginModal-header">
<img id="login_modal_image" class="LoginModal-logoImage"
ng-class="{'LoginModal-logoImage--notCustom': !customLogoPresent}"

View File

@ -3,14 +3,14 @@
<a id="main_menu_logo"
href="/#/"
class="MainMenu-logo ng-cloak"
ng-class="{'is-loggedOut' : !$root.current_user.username, 'MainMenu-logoImage--licenseMissing': licenseMissing}">
ng-class="{'is-loggedOut' : !current_user || !current_user.username, 'MainMenu-logoImage--licenseMissing': licenseMissing}">
<img class="MainMenu-logoImage"
ng-class="{'MainMenu-logoImage--licenseMissing': licenseMissing}"
ng-src="/static/assets/tower-logo-header.svg">
</a>
<!-- Mobile menu items -->
<span id="main_menu_mobile_items" class="MainMenu-mobileItems" ng-class="{'is-hiddenOnMobile': isHiddenOnMobile, 'is-loggedOut' : !$root.current_user.username}">
<span id="main_menu_mobile_items" class="MainMenu-mobileItems" ng-class="{'is-hiddenOnMobile': isHiddenOnMobile, 'is-loggedOut' : !current_user || !current_user.username}">
<a class="MainMenu-item"
id="main_menu_projects_mobile_link"
href="/#/projects"
@ -90,7 +90,7 @@
id="main_menu_projects_link"
href="/#/projects"
ng-hide="licenseMissing"
ng-class="{'is-currentRoute' : isCurrentState('projects'), 'is-loggedOut' : !$root.current_user.username}">
ng-class="{'is-currentRoute' : isCurrentState('projects'), 'is-loggedOut' : !current_user || !current_user.username}">
<span class="MainMenu-itemText">
PROJECTS
</span>
@ -99,7 +99,7 @@
id="main_menu_inventories_link"
href="/#/inventories"
ng-hide="licenseMissing"
ng-class="{'is-currentRoute' : isCurrentState('inventories'), 'is-loggedOut' : !$root.current_user.username}">
ng-class="{'is-currentRoute' : isCurrentState('inventories'), 'is-loggedOut' : !current_user || !current_user.username}">
<span class="MainMenu-itemText">
INVENTORIES
</span>
@ -108,7 +108,7 @@
id="main_menu_job_templates_link"
href="/#/job_templates"
ng-hide="licenseMissing"
ng-class="{'is-currentRoute' : isCurrentState('jobTemplates'), 'is-loggedOut' : !$root.current_user.username}">
ng-class="{'is-currentRoute' : isCurrentState('jobTemplates'), 'is-loggedOut' : !current_user || !current_user.username}">
<span class="MainMenu-itemText">
JOB TEMPLATES
</span>
@ -117,7 +117,7 @@
id="main_menu_jobs_link"
href="/#/jobs"
ng-hide="licenseMissing"
ng-class="{'is-currentRoute' : isCurrentState('jobs'), 'is-loggedOut' : !$root.current_user.username}">
ng-class="{'is-currentRoute' : isCurrentState('jobs'), 'is-loggedOut' : !current_user || !current_user.username}">
<span class="MainMenu-itemText">
JOBS
</span>
@ -126,7 +126,7 @@
id="main_menu_current_user_link"
ng-href="/#/users/{{ $root.current_user.id }}"
ng-hide="licenseMissing"
ng-class="{'is-currentRoute' : isCurrentState('users.edit'), 'is-loggedOut' : !$root.current_user.username}"
ng-class="{'is-currentRoute' : isCurrentState('users.edit'), 'is-loggedOut' : !current_user || !current_user.username}"
aw-tool-tip="{{currentUserTip}}"
aw-tip-watch="currentUserTip"
data-placement="bottom"
@ -143,7 +143,7 @@
id="main_menu_setup_link"
ng-href="/#/setup"
ng-hide="licenseMissing"
ng-class="{'is-currentRoute' : isCurrentState('setup'), 'is-loggedOut' : !$root.current_user.username}"
ng-class="{'is-currentRoute' : isCurrentState('setup'), 'is-loggedOut' : !current_user || !current_user.username}"
aw-tool-tip="Settings"
data-placement="bottom"
data-trigger="hover"
@ -156,7 +156,7 @@
id="main_menu_portal_link"
ng-href="/#/portal"
ng-hide="licenseMissing"
ng-class="{'is-currentRoute' : isCurrentState('portalMode'), 'is-loggedOut' : !$root.current_user.username}"
ng-class="{'is-currentRoute' : isCurrentState('portalMode'), 'is-loggedOut' : !current_user || !current_user.username}"
aw-tool-tip="My View"
data-placement="bottom"
data-trigger="hover"
@ -169,7 +169,7 @@
id="main_menu_docs_link"
ng-href="http://docs.ansible.com/ansible-tower/"
ng-hide="licenseMissing"
ng-class="{'is-loggedOut' : !$root.current_user.username}"
ng-class="{'is-loggedOut' : !current_user || !current_user.username}"
aw-tool-tip="View Documentation"
data-placement="bottom"
data-trigger="hover"
@ -183,7 +183,7 @@
id="main_menu_logout_link"
ng-href="/#/logout"
ng-class="{'is-currentRoute' : isCurrentState('logout'),
'is-loggedOut' : !$root.current_user.username,
'is-loggedOut' : !current_user || !current_user.username,
'MainMenu-item--licenseMissing' : licenseMissing}"
aw-tool-tip="Log Out"
data-placement="bottom"
@ -205,7 +205,7 @@
data-placement="bottom"
data-trigger="hover"
data-container="body"
ng-class="{'is-loggedOut' : !$root.current_user.username}"
ng-class="{'is-loggedOut' : !current_user || !current_user.username}"
ng-hide="licenseMissing"
ng-if="socketStatus && socketStatus !== 'ok'">
<i class="fa MainMenu-socketImage"
@ -218,7 +218,7 @@
id="main_menu_mobile_toggle_button"
class="MainMenu-toggle"
ng-hide="licenseMissing"
ng-class="{'is-active': !isHiddenOnMobile, 'is-loggedOut' : !$root.current_user.username}"
ng-class="{'is-active': !isHiddenOnMobile, 'is-loggedOut' : !current_user || !current_user.username}"
ng-click="toggleMenu()">
<i class="fa fa-bars MainMenu-toggleImage"></i>
</button>