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

@ -18,6 +18,18 @@
$scope.error = $window.location.hash.substr(7); $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. * UserCtrl is responsible for managing user settings.
*/ */
@ -115,6 +127,7 @@
.module('drone') .module('drone')
.controller('UserHeaderCtrl', UserHeaderCtrl) .controller('UserHeaderCtrl', UserHeaderCtrl)
.controller('UserLoginCtrl', UserLoginCtrl) .controller('UserLoginCtrl', UserLoginCtrl)
.controller('UserLogoutCtrl', UserLogoutCtrl)
.controller('UserCtrl', UserCtrl) .controller('UserCtrl', UserCtrl)
.controller('UsersCtrl', UsersCtrl); .controller('UsersCtrl', UsersCtrl);
})(); })();

View file

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

View file

@ -15,6 +15,7 @@
<ul> <ul>
<li><a href="/profile">Profile</a></li> <li><a href="/profile">Profile</a></li>
<li><a href="/users">Users</a></li> <li><a href="/users">Users</a></li>
<li><a href="/logout">Logout</a></li>
</ul> </ul>
</div> </div>
</li> </li>