 usernameFormMessages = new FormMessages()
+usernameLastValue = null
 usernameReadyForValidation = false
 usernameFieldModified = false
 usernameSubmitted = false
 
 passwordFormMessages = new FormMessages()
+currentPasswordLastValue = null
+newPasswordLastValue = null
 newPasswordReadyForValidation = false
 newPasswordFieldModified = false
 

    callback error
    return

  try
    # We check this manually because changePassword error throws global 'Match failed' error if current password is empty string
    throw new ValidationError "Incorrect password.", 'current-password' unless currentPassword
    Accounts.changePassword currentPassword, newPassword, (error) ->
      formError = new ValidationError (error.reason or error.toString() or "Unknown error"), 'current-password' if error
      callback formError
  catch error
    callback error

Template.settingsBackground.checked = ->
  backgroundPaused = !!Meteor.user().settings?.backgroundPaused

    return # Make sure CoffeeScript does not return anything

  'keyup input.new-password, paste input.new-password': (event, template) ->
    # Proceed only if something really changed
    newValue = $(template.findAll 'input.new-password').val()
    return if newValue is newPasswordLastValue
    newPasswordLastValue = newValue

    passwordFormMessages.resetMessages '' # Reset global messages

    newPasswordFieldModified = true
    newPassword = $(template.findAll 'input.new-password').val()
    validatePassword newPassword, 'new-password'

    return # Make sure CoffeeScript does not return anything

