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.

Revisions

  1. Royedc4 revised this gist Mar 23, 2015. No changes.
  2. Royedc4 created this gist Mar 23, 2015.
    19 changes: 19 additions & 0 deletions gistfile1.coffee
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    // 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'
    ])