Added Logout Function

This commit is contained in:
Sagi Dayan 2015-06-17 20:14:53 +03:00
parent f87a14b2da
commit 3465ff3465

View file

@ -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);
}
}
}]);
]);