Skip to content

Instantly share code, notes, and snippets.

@luin
Created March 7, 2013 17:27
Show Gist options
  • Select an option

  • Save luin/5109927 to your computer and use it in GitHub Desktop.

Select an option

Save luin/5109927 to your computer and use it in GitHub Desktop.
angular.module('projectServices', [])
.factory 'User', ->
@authenticated = false
@name = null
isAuthenticated: => @authenticated
getName: => @name
login: (username, password, callback) =>
$.post '/login',
{username: username, password: password},
((data) =>
if data.result
@name = username
@authenticated = true
callback(data.result)),
'json'
logout: (callback) =>
if @authenticated
$.post '/logout', {},
((data) =>
if data.result
@authenticated = false;
callback(data.result)),
'json'
else callback(false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment