Commit f9ce32e4 authored by Evren Kutar's avatar Evren Kutar

v0.0.3.1 login and logout to work properly fixes

parent 30f6961f
......@@ -36,7 +36,7 @@ var app = angular.module(
if (document.cookie.indexOf("backendurl") > -1){
var cookiearray = document.cookie.split(';');
angular.forEach(cookiearray, function(item){
if(item.indexOf("backendurl")){
if(item.indexOf("backendurl") > -1){
backendurl = item.split('=')[1];
}
});
......
......@@ -44,22 +44,10 @@ app.config(['$routeProvider', function ($routeProvider) {
})
.otherwise({redirectTo: '/dashboard'});
}]).run(function ($rootScope, $location, $cookies) {
/**
* todo: below session id is temporary session_id
* the login logic will be finished when backend complete
*
*/
$rootScope.loggedInUser ? $rootScope.loggedInUser : false;
$rootScope.loggedInUser = true;
$rootScope.$on("$routeChangeStart", function (event, next, current) {
//if ($rootScope.loggedInUser == null) {
// // no logged user, redirect to /login
// if (next.templateUrl === "login/login.html") {
//
// } else {
// $location.path("/login");
// }
//}
// will be used when needed
});
}).config(['$httpProvider', function($httpProvider) {
// to send cookies CORS
......
......@@ -43,7 +43,7 @@ auth.factory('LoginService', function ($http, $rootScope, $location, $log, $cook
.post(RESTURL.url + url, credentials)
.success(function (data, status, headers, config) {
//$window.sessionStorage.token = data.token;
$rootScope.loggedInUser = true;
//$rootScope.loggedInUser = true;
})
.error(function (data, status, headers, config) {
// Erase the token if the user fails to log in
......@@ -69,13 +69,10 @@ auth.factory('LoginService', function ($http, $rootScope, $location, $log, $cook
};
loginService.logout = function() {
console.log("logout");
$http.post(RESTURL.url + 'logout', {}).then(function(){
$rootScope.loggedInUser = false;
$location.path("/login");
});
console.log("loggedout");
};
loginService.isAuthenticated = function () {
......
......@@ -12,6 +12,6 @@
angular.module('ulakbus.dashboard', ['ngRoute'])
.controller('DashCtrl', function ($scope, $rootScope, $location) {
if(!$rootScope.loggedInUser){$location.path("/login");}
//if($rootScope.loggedInUser){$location.path("/login");}
$scope.testData = "<h1>This is main Dashboard</h1>";
});
\ No newline at end of file
......@@ -25,7 +25,7 @@
</head>
<body>
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0" ng-if="$root.loggedInUser">
<ul class="header-menu">
<li><a href="">Mesajlar</a></li>
<li><a href="">Görevler</a></li>
......
......@@ -32,7 +32,7 @@
</head>
<body>
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0" ng-if="$root.loggedInUser">
<ul class="header-menu">
<li><a href="">Mesajlar</a></li>
<li><a href="">Görevler</a></li>
......@@ -115,12 +115,12 @@
<!-- @if NODE_ENV == 'PRODUCTION' -->
<script src="bower_components/jquery.min.js"></script>
<script src="bower_components/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.18/angular.min.js"></script>
<script src="bower_components/components.js"></script>
<script src="shared/translations.js"></script>
<script src="templates.js"></script>
<script src="app.js"></script>
<script src="bower_components/theme.js"></script>
<script src="dist/bower_components/theme.js"></script>
<!-- @endif -->
</body>
</html>
......@@ -41,7 +41,7 @@ var app = angular.module(
if (document.cookie.indexOf("backendurl") > -1){
var cookiearray = document.cookie.split(';');
angular.forEach(cookiearray, function(item){
if(item.indexOf("backendurl")){
if(item.indexOf("backendurl") > -1){
backendurl = item.split('=')[1];
}
});
......
......@@ -16,7 +16,6 @@ app.directive('logout', function ($http, $location, RESTURL) {
$rootScope.loggedInUser = false;
console.log($rootScope.loggedInUser);
$location.path("/login");
$scope.$apply();
});
});
}
......@@ -71,12 +70,20 @@ app.directive('sidebar', ['$location', function () {
restrict: 'E',
replace: true,
scope: {},
controller: function ($scope, $http, RESTURL) {
controller: function ($scope, $rootScope, $http, RESTURL, $location) {
$rootScope.$watch(
$rootScope.loggedInUser, function(){
$http.post(RESTURL.url + 'crud/').success(function (data) {
$scope.menuItems = data.app_models;
});
}
);
//$http.post(RESTURL.url + 'crud/').success(function (data) {
// $scope.menuItems = data.app_models;
//});
$scope.selectedMenu = 'dashboard';
$scope.selectedMenu = $location.path();
$scope.collapseVar = 0;
$scope.multiCollapseVar = 0;
......
<div class="manager-view-header container-fluid">
<div class="manager-view-header container-fluid" ng-class="{hidden: $root.loggedInUser != true}">
<header-breadcrumb></header-breadcrumb>
<div id="header-buttons">
<button type="button" class="btn btn-primary" ng-click="triggerSubmit()">Kaydet</button>
......
......@@ -3,7 +3,7 @@
<div class="brand">
<a href="" class="logo"><img src="/img/brand-logo.png" /></a>
</div>
<ul class="nav in sidebarscroll" id="side-menu">
<ul class="nav in sidebarscroll" id="side-menu" ng-class="{hidden: $root.loggedInUser != true}">
<!--<sidebar-search></sidebar-search>-->
<li ui-sref-active="active">
<a href="#/dashboard"><i class="fa fa-dashboard fa-fw"></i> Panel</a>
......
......@@ -24,13 +24,18 @@ app.config(['$httpProvider', function ($httpProvider) {
},
'response': function (response) {
//Will only be called for HTTP up to 300
if(response.data.is_login===true){
if(response.data.is_login == false){
$rootScope.loggedInUser = response.data.is_login;
//$location.replace();
$location.path("/login");
}
if(response.data.is_login == true){
$rootScope.loggedInUser = true;
if($location.path()==="/login"){
$location.path("/dashboard");
}
}
if(response.data.client_cmd) {
//$location.path(response.data.screen);
console.log(response.data.client_cmd);
......@@ -43,7 +48,7 @@ app.config(['$httpProvider', function ($httpProvider) {
$location.reload();
}
if(rejection.status === 401) {
$rootScope.loggedInUser = false;
//$rootScope.loggedInUser = false;
if($location.path()==="/login"){
console.log("show errors on login form");
} else{
......
This diff is collapsed.
......@@ -20,7 +20,7 @@
</head>
<body>
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0" ng-if="$root.loggedInUser">
<ul class="header-menu">
<li><a href="">Mesajlar</a></li>
<li><a href="">Görevler</a></li>
......@@ -59,11 +59,11 @@
<script src="bower_components/jquery.min.js"></script>
<script src="bower_components/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.18/angular.min.js"></script>
<script src="bower_components/components.js"></script>
<script src="shared/translations.js"></script>
<script src="templates.js"></script>
<script src="app.js"></script>
<script src="bower_components/theme.js"></script>
<script src="dist/bower_components/theme.js"></script>
</body>
</html>
......@@ -925,7 +925,7 @@ angular.module("shared/templates/directives/header-notification.html", []).run([
angular.module("shared/templates/directives/header-sub-menu.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("shared/templates/directives/header-sub-menu.html",
"<div class=\"manager-view-header container-fluid\">\n" +
"<div class=\"manager-view-header container-fluid\" ng-class=\"{hidden: $root.loggedInUser != true}\">\n" +
" <header-breadcrumb></header-breadcrumb>\n" +
" <div id=\"header-buttons\">\n" +
" <button type=\"button\" class=\"btn btn-primary\" ng-click=\"triggerSubmit()\">Kaydet</button>\n" +
......@@ -1002,7 +1002,7 @@ angular.module("shared/templates/directives/sidebar.html", []).run(["$templateCa
" <div class=\"brand\">\n" +
" <a href=\"\" class=\"logo\"><img src=\"/img/brand-logo.png\" /></a>\n" +
" </div>\n" +
" <ul class=\"nav in sidebarscroll\" id=\"side-menu\">\n" +
" <ul class=\"nav in sidebarscroll\" id=\"side-menu\" ng-class=\"{hidden: $root.loggedInUser != true}\">\n" +
" <!--<sidebar-search></sidebar-search>-->\n" +
" <li ui-sref-active=\"active\">\n" +
" <a href=\"#/dashboard\"><i class=\"fa fa-dashboard fa-fw\"></i> Panel</a>\n" +
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment