<commit_before>app.config(function($routeProvider, $locationProvider){

	$locationProvider.html5Mode(false);

	$routeProvider
		.when('/login', {
			controller: 'loginController',
			templateUrl: SETTINGS.views() + 'login.html',
			resolve: {
				isLoggedIn: checkLogin
			}
		})
		.when('/', {
			controller: 'homeController',
			templateUrl: SETTINGS.views() + 'home.html',
			resolve: {
				isLoggedIn: checkLogin
			}
		})
		.when('/cart', {
			controller: 'cartController',
			templateUrl: SETTINGS.views() + 'cart.html',
			resolve: {
				isLoggedIn: checkLogin
				//exists : checkPage
			}
		})
		.when('/checkout', {
			controller: 'checkoutController',
			templateUrl: SETTINGS.views() + 'checkout.html',
			resolve: {
				isLoggedIn: checkLogin
				//exists : checkPage
			}
		})
		.when('/checkout/success', {
			controller: 'successController',
			templateUrl: SETTINGS.views() + 'success.html',
			resolve: {
				isLoggedIn: checkLogin
				//exists : checkPage
			}
		})
		.when('/invoice', {
			controller: 'invoiceController',
			templateUrl: SETTINGS.views() + 'invoice.html',
			resolve: {
				isLoggedIn: checkLogin
				//exists : checkPage
			}
		})
		.when('/:category*/p/:product', {
			controller: 'productController',
			templateUrl: SETTINGS.views() + 'product.html',
			resolve: {
				isLoggedIn: checkLogin,
				exists : function(check) {return check.category()}
			}
		})
		.when('/:category*', {
			controller: 'categoryController',
			templateUrl: SETTINGS.views() + 'category.html',
			resolve: {
				isLoggedIn: checkLogin,
				exists : function(check) {return check.category()}
			}
		})
		
		// .when('/:page/:subpage', {
		// 	controller: 'pageController',
		// 	templateUrl: SETTINGS.views() + 'page.html',
		// 	resolve: {
		// 		isLoggedIn: checkLogin,
		// 		exists : function(check) {return check.category()}
		// 	}
		// })
		.when('/404', {
			controller: 'homeController',
			templateUrl: SETTINGS.views() + 'home.html',
			resolve: {
				isLoggedIn: checkLogin
			}
		})
		.otherwise({
			redirectTo: '/404'
		});
});

checkLogin = function() {
	if (USER.admin) {
		console.log('You\'re loggen in as admin');
	}
	else {
		console.log("You are nobody");
	}
}

app.factory('check', function($location, $routeParams, api) {
	return {
		category : function(path) {
			console.log($location.path())
			api.post("checkpage", path).then(function(response) {
				console.log(response);
			});
		},
		product : function(path) {
			api.post("checkpage", path).then(function(response) {
				console.log(response);
			})
		}
	}
	// if ($routeParams.page != "login" || $routeParams.page != "404") {
	// 	$location.path("/404");
	// }
})

app.run(function($rootScope, $location) {
    $rootScope.$on( "$routeChangeStart", function(event, next, current) {
      if (!USER.admin) {
        // no logged user, redirect to /login
        if ( next.templateUrl === "partials/login.html") {
        } else {
          $location.path("/login");
        }
      }
    });
  });<commit_msg>ADD: new routes and authentication<commit_after>app.config(function($routeProvider, $locationProvider){

	$locationProvider.html5Mode(false);

	$routeProvider
		.when('/', {
			controller: 'homeController',
			templateUrl: SETTINGS.views() + 'home.html',
			resolve: {
			}
		})
		.when('/login', {
			controller: 'loginController',
			templateUrl: SETTINGS.views() + 'login.html',
			resolve: {
			}
		})
		.when('/cart', {
			controller: 'cartController',
			templateUrl: SETTINGS.views() + 'cart.html',
			resolve: {
				//exists : checkPage
			}
		})
		.when('/checkout', {
			controller: 'checkoutController',
			templateUrl: SETTINGS.views() + 'checkout.html',
			resolve: {
				//exists : checkPage
			}
		})
		.when('/checkout/success', {
			controller: 'successController',
			templateUrl: SETTINGS.views() + 'success.html',
			resolve: {
				//exists : checkPage
			}
		})
		.when('/invoice', {
			controller: 'invoiceController',
			templateUrl: SETTINGS.views() + 'invoice.html',
			resolve: {
				//exists : checkPage
			}
		})
		.when('/admin', {
			controller: 'ordersController',
			templateUrl: SETTINGS.views() + 'admin.html',
			resolve: {
				//exists : function() {return check.admin()}
			}
		})
		.when('/admin/orders', {
			controller: 'ordersController',
			templateUrl: SETTINGS.views() + 'orders.html',
			resolve: {
				//exists : function() {return check.admin()}
			}
		})
		.when('/admin/orders/:order_id', {
			controller: 'orderDetailController',
			templateUrl: SETTINGS.views() + 'orderDetail.html',
			resolve: {
				//exists : function() {return check.admin()}
			}
		})
		.when('/:category*/p/:product', {
			controller: 'productController',
			templateUrl: SETTINGS.views() + 'product.html',
			resolve: {
			//	exists : function() {return check.category()}
			}
		})
		.when('/:category*', {
			controller: 'categoryController',
			templateUrl: SETTINGS.views() + 'category.html',
			resolve: {
				//exists : function() {return check.category()}
			}
		})
		
		// .when('/:page/:subpage', {
		// 	controller: 'pageController',
		// 	templateUrl: SETTINGS.views() + 'page.html',
		// 	resolve: {
		// 		isLoggedIn: checkLogin,
		// 		exists : function(check) {return check.category()}
		// 	}
		// })
		.when('/404', {
			controller: 'homeController',
			templateUrl: SETTINGS.views() + 'home.html',
			resolve: {
//				isLoggedIn: checkLogin
			}
		})
		.otherwise({
			redirectTo: '/404'
		});
});

app.service('check', function($location, $routeParams, api, auth) {
	return {
		category : function(path) {
			console.log($location.path())
			api.post("checkpage", path).then(function(response) {
				console.log(response);
			});
		},
		product : function(path) {
			api.post("checkpage", path).then(function(response) {
				console.log(response);
			})
		},
		admin : function() {
			if (auth.user.admin) {
				api.post("checklogin", auth).then(function (response) {
					console.log(response)
				})
			}
		}
	}
	// if ($routeParams.page != "login" || $routeParams.page != "404") {
	// 	$location.path("/404");
	// }
})

app.run(function($rootScope, $location, auth, api) {
    $rootScope.$on( "$routeChangeStart", function(event, next, current) {
    	auth.get();
		if (next.controller == "adminController" || next.controller == "ordersController" || next.controller == "orderDetailController") {
			if(!auth.user.admin) {
				$location.path("/");
			}

			api.post("checklogin", auth.user.cred.session).then(function (response) {
				console.log(response)
				if (response != "1")
					$location.path("/")
			})

		}
      if (!USER.admin) {
        // no logged user, redirect to /login
        if ( next.templateUrl === "partials/login.html") {
        } else {
          $location.path("/login");
        }
      }
    });
  });

app.directive('showtab',
    function () {
        return {
            link: function (scope, element, attrs) {
                element.click(function(e) {
                    e.preventDefault();
                    $(element).tab('show');
                });
            }
        };
    });
{'fraction_non_alphanumeric': 0.18506493506493507, 'fraction_numerical': 0.003811405985319029, 'mean_word_length': 2.87582056892779, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6284863', 'n_tokens_mistral': 2757, 'n_tokens_neox': 2346, 'n_words': 392}