Integrated logout button into the UI

This commit is contained in:
Thomas Boerger 2015-08-27 09:44:46 +02:00
parent d1b36e868a
commit 2577b6cda2
3 changed files with 30 additions and 5 deletions

View file

@ -6,10 +6,10 @@
$scope.user = payload.data;
});
$scope.number = $stateParams.number || undefined;
$scope.owner = $stateParams.owner || undefined;
$scope.name = $stateParams.name || undefined;
$scope.full_name = $scope.owner + '/' + $scope.name;
$scope.number = $stateParams.number || undefined;
$scope.owner = $stateParams.owner || undefined;
$scope.name = $stateParams.name || undefined;
$scope.full_name = $scope.owner + '/' + $scope.name;
}
function UserLoginCtrl($scope, $window) {
@ -18,6 +18,18 @@
$scope.error = $window.location.hash.substr(7);
}
function UserLogoutCtrl($scope, $window, $state) {
// Remove login information from the local
// storage and redirect to login page
if (localStorage.hasOwnProperty("access_token")) {
localStorage.removeItem("access_token");
}
$state.go("login", {}, {
location: "replace"
});
}
/**
* UserCtrl is responsible for managing user settings.
*/
@ -115,6 +127,7 @@
.module('drone')
.controller('UserHeaderCtrl', UserHeaderCtrl)
.controller('UserLoginCtrl', UserLoginCtrl)
.controller('UserLogoutCtrl', UserLogoutCtrl)
.controller('UserCtrl', UserCtrl)
.controller('UsersCtrl', UsersCtrl);
})();

View file

@ -89,6 +89,17 @@
},
title: 'Login'
})
.state('logout', {
url: '/logout',
views: {
'layout': {
templateUrl: '/static/scripts/views/login.html',
controller: 'UserLogoutCtrl',
resolve: resolveUser
}
},
title: 'Logout'
})
.state('app.profile', {
url: '/profile',
views: {

View file

@ -15,6 +15,7 @@
<ul>
<li><a href="/profile">Profile</a></li>
<li><a href="/users">Users</a></li>
<li><a href="/logout">Logout</a></li>
</ul>
</div>
</li>
@ -71,4 +72,4 @@ header li {
.dropdown li > a:hover {
background:#F5F7F9;
}
</style>
</style>