From 2577b6cda26d0938da9ee932b4c550f7614f3df2 Mon Sep 17 00:00:00 2001 From: Thomas Boerger Date: Thu, 27 Aug 2015 09:44:46 +0200 Subject: [PATCH] Integrated logout button into the UI --- .../static/scripts/controllers/users.js | 21 +++++++++++++++---- cmd/drone-server/static/scripts/drone.js | 11 ++++++++++ .../static/scripts/views/layout.html | 3 ++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/cmd/drone-server/static/scripts/controllers/users.js b/cmd/drone-server/static/scripts/controllers/users.js index d0849b3df..8a25254bc 100644 --- a/cmd/drone-server/static/scripts/controllers/users.js +++ b/cmd/drone-server/static/scripts/controllers/users.js @@ -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); })(); diff --git a/cmd/drone-server/static/scripts/drone.js b/cmd/drone-server/static/scripts/drone.js index 1e9a796b5..09969f40c 100644 --- a/cmd/drone-server/static/scripts/drone.js +++ b/cmd/drone-server/static/scripts/drone.js @@ -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: { diff --git a/cmd/drone-server/static/scripts/views/layout.html b/cmd/drone-server/static/scripts/views/layout.html index b57bccb8e..ced66f796 100644 --- a/cmd/drone-server/static/scripts/views/layout.html +++ b/cmd/drone-server/static/scripts/views/layout.html @@ -15,6 +15,7 @@ @@ -71,4 +72,4 @@ header li { .dropdown li > a:hover { background:#F5F7F9; } - \ No newline at end of file +