Skip to content

Commit

Permalink
Changed the way logout works. Preventing access to secured pages and …
Browse files Browse the repository at this point in the history
…forcing redirect to login page.
  • Loading branch information
pbuda committed Jan 24, 2013
1 parent bc3b322 commit 31a1fba
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
12 changes: 11 additions & 1 deletion bootstrap-ui/src/main/webapp/app/application.js
Expand Up @@ -14,7 +14,7 @@ angular.module('smlBootstrap', ['smlBootstrap.services', 'smlBootstrap.filters',
when("/error", {controller: 'EntriesController', templateUrl: "partials/errorpages/error500.html"}).
when("/recover-lost-password", {controller: 'PasswordRecoveryController', templateUrl: "partials/recover-lost-password.html"}).
when("/password-reset", {controller: "PasswordRecoveryController", templateUrl: "partials/password-reset.html"}).
when("/profile", {controller: "ProfileController", templateUrl: "partials/profile.html"}).
when("/profile", {controller: "ProfileController", templateUrl: "partials/secured/profile.html"}).
otherwise({redirectTo: '/error404'});
})

Expand Down Expand Up @@ -65,6 +65,16 @@ angular.module('smlBootstrap', ['smlBootstrap.services', 'smlBootstrap.filters',
showInfoMessage(message);
}
});
})

.run(function ($rootScope, UserSessionService, $location) {
$rootScope.$on("$routeChangeStart", function (event, next, current) {
if (!UserSessionService.isLogged() && next.templateUrl.indexOf("/secured/") > -1) {
$location.path("/login");
} else if (UserSessionService.isLogged() && next.templateUrl === "partials/login.html") {
$location.path("/");
}
});
});


Expand Down
8 changes: 5 additions & 3 deletions bootstrap-ui/src/main/webapp/app/controllers.js
Expand Up @@ -23,7 +23,7 @@ controllers.controller('UptimeController', function UptimeController($scope, $ti

});

controllers.controller('EntriesController', function EntriesController($scope, $timeout, $window, EntriesService, UserSessionService) {
controllers.controller('EntriesController', function EntriesController($scope, $timeout, $window, EntriesService, UserSessionService, $location) {

var self = this;

Expand Down Expand Up @@ -108,8 +108,10 @@ controllers.controller('EntriesController', function EntriesController($scope, $
};

$scope.logout = function () {
UserSessionService.logout();
showInfoMessage("Logged out successfully");
UserSessionService.logout(function(data) {
showInfoMessage("Logged out successfully");
$location.path("/");
});
};
});

Expand Down

0 comments on commit 31a1fba

Please sign in to comment.