Created
March 23, 2015 19:13
-
-
Save Royedc4/9891e6f498737f5fd025 to your computer and use it in GitHub Desktop.
This shows an example of the app logic to manage authentication on angularjs
This file contains hidden or 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
| // AUTHENTICATION ON ANGULARJS | |
| .run([ | |
| '$rootScope', 'AUTH_EVENTS', 'LoginService', 'logger', '$location' | |
| ($rootScope, AUTH_EVENTS, LoginService, logger, $location) -> | |
| $rootScope.$on '$routeChangeStart', (event,next) -> | |
| authorizedRoles = next.data.authorizedRoles | |
| if !LoginService.isAuthorized(authorizedRoles) | |
| event.preventDefault() | |
| if LoginService.isAuthenticated() | |
| # User is not a11owed | |
| $rootScope.$broadcast AUTH_EVENTS.notAuthorized | |
| logger.logError('No tienes la permisología para acceder!') | |
| else | |
| # User is not logged in | |
| $rootScope.$broadcast AUTH_EVENTS.notAuthenticated | |
| logger.logError('Debes estar autenticado para ingresar al sistema!') | |
| $location.path '/accounts/signIn' | |
| ]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment