Skip to content

Instantly share code, notes, and snippets.

@prettymuchbryce
Created February 5, 2014 06:03
Show Gist options
  • Save prettymuchbryce/8818148 to your computer and use it in GitHub Desktop.
Save prettymuchbryce/8818148 to your computer and use it in GitHub Desktop.
app.factory('userService', ['$q', '$timeout', '$http', '$rootScope', function($q, $timeout, $http, $rootScope) {
var userService = {};
userService.tryLoginFromCookie = function() {
var promise = $q.defer();
$http({method: 'POST', url: '/login'}).
success(function(data, status, headers, config) {
$timeout(function() {
$rootScope.$broadcast('login', data);
});
}).
error(function(data, status, headers, config) {
console.log("Error");
// called asynchronously if an error occurs
// or server returns response with an error status.
});
return promise;
};
userService.login = function() {
};
userService.register = function() {
};
userService.logout = function() {
};
return userService;
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment