Skip to content

Instantly share code, notes, and snippets.

@kn0ll
Created February 28, 2013 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kn0ll/5054289 to your computer and use it in GitHub Desktop.
Save kn0ll/5054289 to your computer and use it in GitHub Desktop.
a session model for brainy
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