Created
March 7, 2013 17:27
-
-
Save luin/5109927 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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