     ->
       # checking if token is valid
       JApiToken.one { code : token }, (err, apiToken_) ->
+
         if err
           return callback { statusCode : 500, message : 'an error occurred' }
+
         unless apiToken_
           return callback { statusCode : 400, message : 'invalid token!' }
+
         apiToken = apiToken_
         queue.next()
 


validateData = (data, callback) ->

  { JUser, JApiToken } = koding.models
  { token, username }  = data

  apiToken = null


      username or= "#{apiToken.group.substring(0, 4)}#{hat(32)}"
      # checking if username is available
      JUser.usernameAvailable username, (err, { kodingUser, forbidden }) ->

        if err
          return callback { statusCode : 500, message : 'an error occurred' }

        if kodingUser or forbidden
          return callback { statusCode : 400, message : 'username is not available' }

        queue.next()

    ->
      # checking if apiToken is enabled for the Group
      JGroup.one { slug : apiToken.group }, (err, group) ->

        if err
          return callback { statusCode : 500, message : 'an error occurred' }

        unless group
          return callback { statusCode : 400, message : 'group does not exist!' }

        unless group.isApiTokenEnabled is true
          return callback { statusCode : 403, message : 'api token usage is not enabled for this group' }

        queue.next()

    -> callback null, { apiToken, username }
