Created
February 28, 2013 04:53
-
-
Save kn0ll/5054289 to your computer and use it in GitHub Desktop.
a session model for brainy
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
define [ | |
'backbone', | |
'resources/user' | |
], (Backbone, User) -> | |
class extends Backbone.Model | |
idAttribute: '_id' | |
urlRoot: '/sessions' | |
defaults: | |
user_id: undefined | |
validate: (attrs) -> | |
if not attrs.user_id | |
'user_id cannot be empty' | |
else | |
undefined | |
save: (attrs, options = {}) -> | |
user = new User | |
_id: attrs.user_id | |
user.fetch | |
data: | |
password: attrs.password | |
success: => | |
delete attrs.password | |
Backbone.Model::save.apply @, [attrs, options] | |
error: (model) -> | |
options.error? model, 'no user with that user_id and password' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment