Skip to content

Instantly share code, notes, and snippets.

@gocreating
Created August 4, 2014 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gocreating/629583a34618b5b50f02 to your computer and use it in GitHub Desktop.
Save gocreating/629583a34618b5b50f02 to your computer and use it in GitHub Desktop.
// service.js
app
.factory('authService', ['$http', function ($http) {
var auth = {
isAuth: false,
user: null
};
$http
.get('/api/session')
.success(function (data) {
auth.isAuth = data.value.isAuth;
auth.user = data.value.user;
return auth;
});
}]);
// app.js
app.run(function ($location, $rootScope, $route, authService) {
$rootScope.$on('$routeChangeStart', function(evt, next, current) {
if (next.requireAuth && !authService.isAuth) {
next.templateUrl = 'views/special/403.html';
}
});
});
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/user/:user_id/group', {requireAuth: true, controller: 'groupIndexCtrl', templateUrl: 'views/group/index.html'});
$routeProvider.when('/group/new', {requireAuth: true, controller: 'groupNewCtrl', templateUrl: 'views/group/new.html'});
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment