 Encoder = require 'htmlencode'
 VerifyPINModal = require 'app/commonviews/verifypinmodal'
 VerifyPasswordModal = require 'app/commonviews/verifypasswordmodal'
-sinkrow = require 'sinkrow'
+async = require 'async'
 KodingSwitch = require 'app/commonviews/kodingswitch'
 
 

          "profile.lastName" : lastName
          "shareLocation"    : formData.shareLocation
        }, (err)->
          return notify err.message  if err
          me.shareLocation = formData.shareLocation
          queue.next()
      =>
        return queue.next() if email is @userInfo.email

        options = {skipPasswordConfirmation, email}
        @confirmCurrentPassword options, (err) =>
          if err
            notify err
            profileUpdated = false
            return queue.next()

          JUser.changeEmail {email}, (err, result)=>
            if err
              @hideSaveButtonLoader()
              notify err.message
              return queue.next()

            skipPasswordConfirmation = true
            modal = new VerifyPINModal 'Update E-Mail', (pin)=>
              remote.api.JUser.changeEmail {email, pin}, (err)=>
                if err
                  notify err.message
                  profileUpdated = false
                else
                  @userInfo.email = email
                queue.next()
            modal.once 'ModalCancelled', @bound 'hideSaveButtonLoader'
      =>
        # on third turn update password
        # check for password confirmation
        if password isnt confirmPassword
          notify "Passwords did not match"
          @hideSaveButtonLoader()
          return
        #check passworg lenght
        if password isnt "" and password.length < 8
          notify "Passwords should be at least 8 characters"
          @hideSaveButtonLoader()
          return
        # if password is empty than discard operation
        if password is ""
          {token} = kd.utils.parseQuery()
          if token
            profileUpdated = no
            notify "You should set your password"
          return queue.next()

        JUser.fetchUser (err, user)=>
          if err
            notify "An error occurred"
            return queue.next()

          skipPasswordConfirmation = true  if user.passwordStatus isnt "valid"
          @confirmCurrentPassword {skipPasswordConfirmation}, (err) =>
            if err
              notify err
              profileUpdated = false
              return queue.next()
            JUser.changePassword password, (err,docs)=>
              @userProfileForm.inputs.password.setValue ""
              @userProfileForm.inputs.confirm.setValue ""
              if err
                return queue.next()  if err.message is "PasswordIsSame"
                return notify err.message
              return queue.next()
      =>
        # if everything is OK or didnt change, show profile updated modal
        notify "Your account information is updated." if profileUpdated
        @hideSaveButtonLoader()
    ]
    sinkrow.daisy queue

  verifyUserEmail: ->



    {JUser} = remote.api
    {email, password, confirmPassword, firstName, lastName, username, shareLocation} = formData
    skipPasswordConfirmation = no
    queue = [
      (next) ->
        # update firstname and lastname
        me = whoami()

