summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/models/session.js.coffee
blob: 37e98e3bd0c25b136b92220b0e7268424fee9688 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#= require ./translation

class csx.Models.Session extends Backbone.Model
  modelKey: 'session'
  translation: new csx.Translation('session')
  defaults:
    email: null
    password: null

  requiredFields: ['email', 'password']

  validate: (attributes, options) ->
    errors = {}

    unless new csx.Models.Email(attributes.email).isValid()
      errors['email'] = @translation.errorFor('email', 'invalid')

    _.each @requiredFields, (field) =>
      if _.isEmpty(attributes[field])
        errors[field] = @translation.errorFor(field, 'blank')

    return errors if _.keys(errors).length > 0