From 3465ff3465acc33c4aaafd934791c61fc0de7f39 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Wed, 17 Jun 2015 20:14:53 +0300 Subject: [PATCH] Added Logout Function --- templates/js/controllers/mainController.js | 150 +++++++++++---------- 1 file changed, 79 insertions(+), 71 deletions(-) diff --git a/templates/js/controllers/mainController.js b/templates/js/controllers/mainController.js index bad88a9..9b4a18d 100644 --- a/templates/js/controllers/mainController.js +++ b/templates/js/controllers/mainController.js @@ -1,78 +1,86 @@ angular.module('SeHub') - .controller('mainController', ['$scope', '$rootScope', 'apiService', '$cookies', '$location', function($scope, $rootScope, apiService, $cookies, $location) { + .controller('mainController', ['$scope', '$rootScope', 'apiService', '$cookies', '$cookieStore', '$location', '$window', - var token = $cookies['com.sehub.www']; + function($scope, $rootScope, apiService, $cookies, $cookieStore, $location, $window) { - $scope.loadingData = true; - $scope.isInRegisterMode = false; + var token = $cookies['com.sehub.www']; - apiService.getUserByToken(token).success(function(data) { - if (data.message == 'No User Found') { - console.error("No User Found!"); - } - $scope.loadingData = false; - $scope.user = data; - console.log(data); - if ($scope.user.isFirstLogin) { - $scope.menuObj = {}; - $scope.isInRegisterMode = true; - $scope.loadingData = false; - $location.path('/register') - } else { - $location.path('/home') - } + $scope.loadingData = true; + $scope.isInRegisterMode = false; - }) - - $scope.menuItems = [{ - "title": "Home", - "icon": "fa fa-home", - "style": "selected", - "route": "/home" - }, { - "title": "My Campuses", - "icon": "fa fa-university", - "style": "", - "route": "/campuses" - }, { - "title": "My Classes", - "icon": "fa fa-graduation-cap", - "style": "", - "route": "/campuses" - }, { - "title": "My Projects", - "icon": "fa fa-cube", - "style": "", - "route": "/campuses" - }, { - "title": "Tasks", - "icon": "fa fa-clipboard", - "style": "", - "route": "/campuses" - }, { - "title": "Settings", - "icon": "fa fa-cogs", - "style": "", - "route": "/Settings" - }, { - "title": "Log Out", - "icon": "fa fa-power-off", - "style": "", - "route": "/logout" - }]; - - $scope.menuClicked = function(item){ - var route = "" - for (var i = $scope.menuItems.length - 1; i >= 0; i--) { - if($scope.menuItems[i].title === item.title){ - $scope.menuItems[i].style="selected"; - route = $scope.menuItems[i].route; - }else{ - $scope.menuItems[i].style = ""; + apiService.getUserByToken(token).success(function(data) { + if (data.message == 'No User Found') { + console.error("No User Found!"); } - }; - $location.path(route); + $scope.loadingData = false; + $scope.user = data; + console.log(data); + if ($scope.user.isFirstLogin) { + $scope.menuObj = {}; + $scope.isInRegisterMode = true; + $scope.loadingData = false; + $location.path('/register') + } else { + $location.path('/home') + } + + }) + + $scope.menuItems = [{ + "title": "Dash Board", + "icon": "fa fa-tachometer", + "style": "selected", + "route": "/home" + }, { + "title": "My Campuses", + "icon": "fa fa-university", + "style": "", + "route": "/campuses" + }, { + "title": "My Classes", + "icon": "fa fa-graduation-cap", + "style": "", + "route": "/campuses" + }, { + "title": "My Projects", + "icon": "fa fa-cube", + "style": "", + "route": "/campuses" + }, { + "title": "Tasks", + "icon": "fa fa-clipboard", + "style": "", + "route": "/campuses" + }, { + "title": "Settings", + "icon": "fa fa-cogs", + "style": "", + "route": "/Settings" + }, { + "title": "Log Out", + "icon": "fa fa-power-off", + "style": "", + "route": "/logout" + }]; + + $scope.menuClicked = function(item) { + var route = "" + if (item.title == "Log Out") { + console.info('Logging Out!'); + $cookieStore.remove('com.sehub.www'); + $window.location.href = 'http://se-hub.appspot.com'; // Reference to 'welcome' page + } + for (var i = $scope.menuItems.length - 1; i >= 0; i--) { + if ($scope.menuItems[i].title === item.title) { + $scope.menuItems[i].style = "selected"; + route = $scope.menuItems[i].route; + } else { + $scope.menuItems[i].style = ""; + } + }; + $location.path(route); + } + + } - - - }]); \ No newline at end of file + ]); \ No newline at end of file