Skip to content

Instantly share code, notes, and snippets.

@Royedc4
Created March 23, 2015 19:13
Show Gist options
  • Select an option

  • Save Royedc4/9891e6f498737f5fd025 to your computer and use it in GitHub Desktop.

Select an option

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
// 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