           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
 

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

request     = require "request"

module.exports = class JUser extends jraphical.Module

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

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

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

          queue.next()

      =>
        userInfo =
          email          : email
          username       : username
          password       : password
          lastName       : lastName
          firstName      : firstName
          emailFrequency : 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!'

      ->
        if ip? and country? and region?
          locationModifier =
            $set                       :
              'registeredFrom.ip'      : ip
              'registeredFrom.region'  : region
              'registeredFrom.country' : country

          user.update locationModifier, ->
            queue.next()

        else
          queue.next()

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

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

          @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()

