       =>
         # password is autogenerated before here
         # user should reset his/her password
-        @update { username: oldUsername }, { $set: { 'passwordStatus' : 'needs set' }}, (err, res)=>
+        operation = { $set: passwordStatus: 'needs set' }
+        @update { username: oldUsername }, operation, (err, res)=>
           return callback err  if err
           queue.next()
       =>
-        options = { account, oldUsername, email }
-        @changeEmailByUsername options, (err) =>
-          return callback err  if err?
+        if username? and email?
+          options = { account, oldUsername, email, username }
+          @changeEmailByUsername options, (err) =>
+            return callback err  if err?
+            queue.next()
+        else process.nextTick -> queue.next()
+      ->
+        account.fetchUser (err, user_) ->
+          return callback err  if err
+          user = user_
           queue.next()
       =>
         @persistOauthInfo oldUsername, client.sessionToken, (err)=>
           return callback err  if err
           queue.next()
       =>
-        options = { account, username, clientId, isRegistration: yes }
-        @changeUsernameByAccount options, (err, newToken_) =>
-          return callback err  if err?
-          newToken = newToken_
-          queue.next()
+        if username?
+          options = { account, username, clientId, isRegistration: yes }
+          @changeUsernameByAccount options, (err, newToken_) =>
+            return callback err  if err?
+            newToken = newToken_
+            queue.next()
+        else process.nextTick -> queue.next()
       =>
-        @verifyEnrollmentEligibility {email, inviteCode}, (err, isEligible, invite_) =>
+        @verifyEnrollmentEligibility {email: user.email, inviteCode}, (err, isEligible, invite_) =>
           return callback err  if err
           invite = invite_
           queue.next()
       =>
-        @addToGroups account, invite, email, (err) =>
+        @addToGroups account, invite, user.email, (err) =>
           return callback err  if err?
           queue.next()
       =>


    newToken  = null
    invite    = null

    queue = [
      =>

          queue.next()
      =>
        JPasswordRecovery = require '../passwordrecovery'
        JPasswordRecovery.create client, {email: user.email}, (err)->
          queue.next()
      ->
        JAccount.emit "AccountRegistered", account, referrer
