           queue.next()
 
       ->
-        JUser.emit "UserRegistered", {user, account}
+        JUser.emit 'UserRegistered', { user, account }
         queue.next()
 
       ->
         # Auto confirm accounts for development environment
         # This config should be no for production! ~ GG
         if KONFIG.autoConfirmAccounts
-          user.confirmEmail (err)->
+          user.confirmEmail (err) ->
             console.warn err  if err?
             queue.next()
+
         else
-          options = {username, email, action: "verify-account"}
+          options =
+            email    : email
+            action   : 'verify-account'
+            username : username
 
           JVerificationToken = require '../verificationtoken'
-          JVerificationToken.createNewPin options, (err, confirmation)->
+          JVerificationToken.createNewPin options, (err, confirmation) ->
             if err
-              console.warn "Failed to send verification token:", err
+              console.warn 'Failed to send verification token:', err
             else
               pin = confirmation.pin
 

          queue.next()

      =>
        if aNewRegister

          userInfo = { username, firstName, lastName,
            email, password, emailFrequency }

          @createUser userInfo, (err, _user, _account)=>
            return callback err  if err

            if _user? and _account?

              [account, user] = [_account, _user]
              queue.next()

            else

              return callback new KodingError "Failed to create user!"

        else
          queue.next()

      =>
        if not aNewRegister and username? and email?
          options = { account, oldUsername, email, username }
          @changeEmailByUsername options, (err) =>
            return callback err  if err
            queue.next()
        else
          queue.next()

      ->
        if not aNewRegister
          account.fetchUser (err, user_) ->
            return callback err  if err
            user = user_
            queue.next()
        else
          queue.next()

      ->
        if ip? and country? and region?
          locationModifier = $set    :
            "registeredFrom.ip"      : ip
            "registeredFrom.country" : country
            "registeredFrom.region"  : region
          user.update locationModifier, -> queue.next()
        else
          queue.next()

      =>
        oauthUser = if aNewRegister then username else oldUsername

        @persistOauthInfo oauthUser, client.sessionToken, (err)=>
          return callback err  if err
          queue.next()

      =>
        if aNewRegister and username?
          options = {
            account        : account
            username       : username
            clientId       : clientId
            isRegistration : yes
            groupName      : client.context.group
          }

          @changeUsernameByAccount options, (err, newToken_) =>
            return callback err  if err
            newToken = newToken_
            queue.next()
        else
          queue.next()

      ->
        account.update $set: type: 'registered', (err) ->
          return callback err  if err?
          queue.next()


{ argv }         = require 'optimist'
KONFIG           = require('koding-config-manager').load("main.#{argv.c}")
Regions          = require 'koding-regions'
request          = require "request"
jraphical        = require 'jraphical'
Flaggable        = require '../../traits/flaggable'
KodingError      = require '../../error'
{ extend, uniq } = require 'underscore'


module.exports = class JUser extends jraphical.Module

  { v4: createId }                   = require 'node-uuid'
  { Relationship }                   = jraphical
  { secure, signature, daisy, dash } = require 'bongo'

  JLog                               = require '../log'
  JName                              = require '../name'
  JGroup                             = require '../group'
  Tracker                            = require '../tracker'
  JSession                           = require '../session'
  JAccount                           = require '../account'
  JInvitation                        = require '../invitation'
  JPaymentPlan                       = require '../payment/plan'
  ComputeProvider                    = require '../computeproviders/computeprovider'
  JPaymentSubscription               = require '../payment/subscription'

  @bannedUserList = ['abrt','amykhailov','apache','about','visa','shared-',
                     'cthorn','daemon','dbus','dyasar','ec2-user','http',
