           reject new Error('Enter a valid CVC number')
         resolve value
 
-  agreeToTerms: (value)->
+  agreeToTerms: (value) ->
     if value == true
       return value
 

emailRe = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/

middleware =
  isRequired: (value)->
    return value if value && value != ''

    throw new Error 'Required'

  isEmail: (value)->
    if !value
      return value

    return value.toLowerCase() if emailRe.test value

    throw new Error 'Enter a valid email'

  isNewPassword: (value)->
    if !@get 'user.currentPassword'
      throw new Error 'Current password required' if value
      return value

    return middleware.isPassword value

  isPassword: (value)->
    if !value
      throw new Error 'Required'

    return value if value.length >= 6


    throw new Error 'Passwords must match'

  splitName: (value) ->
    return value unless value

    parts     = value.trim().split ' '
    firstName = parts.shift()
    lastName  = parts.join ' '

    @set 'user.firstName', firstName
    @set 'user.lastName',  lastName

    value

  isEcardGiftRequired: (value) ->
    return value if (!@get('order.gift') || @get('order.giftType') != 'ecard') || (value && value != '')

    throw new Error 'Required'

  requiresStripe: (value) ->
    throw new Error "Required" if @('order.type') == 'stripe' && (!value? || value == '')
    return value

  requireTerms: (value) ->
    if !value
      throw new Error 'Please read and agree to the terms and conditions.'
    value

  cardNumber: (value) ->
    return value unless value

    if @('order.type') != 'stripe'
      return value
