Skip to content

Instantly share code, notes, and snippets.

@pigoz
Created August 7, 2012 12:53
Show Gist options
  • Save pigoz/3285076 to your computer and use it in GitHub Desktop.
Save pigoz/3285076 to your computer and use it in GitHub Desktop.
CheckLoginWithWS = ($http, $location, $rootScope) ->
if !$rootScope.current_user?
PerformLogin($http, $location, $rootScope)
else
$rootScope.$broadcast 'user'
PerformLogin = ($http, $location, $rootScope) ->
$http.get('/api/v1/customers/me.json')
.success (data) ->
if data.uid?
$rootScope.current_user = data
$rootScope.$broadcast 'user'
else
$location.path '/login'
HomeCtrl = ($scope, $http, $location, $rootScope) ->
CheckLoginWithWS($http, $location, $rootScope)
$scope.$on 'user', ->
$location.path '/places'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment