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

class csx.Models.PasswordReset extends Backbone.Model
  translation: new csx.Translation('user')
  defaults:
    email: null

  requiredFields: ['email']

  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