Created
August 4, 2014 18:21
-
-
Save gocreating/629583a34618b5b50f02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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