 
   # validating req params
   { error, token, username, email, firstName, lastName } = validateRequest req
-  return res.status(error.statusCode).send(error.message)  if error
+  return sendApiError res, error  if error
 
   client   = null
   apiToken = null

hat                                = require 'hat'
koding                             = require '../../bongo'
{ daisy }                          = require 'bongo'
{ getClientId
  handleClientIdNotFound
  checkAuthorizationBearerHeader } = require '../../helpers'

module.exports = createUser = (req, res, next) ->


  daisy queue


validateRequest = (req) ->

  token = null
  { username, email, firstName, lastName } = req.body

  unless email
    return { error : apiErrors.invalidInput }

  unless token = checkAuthorizationBearerHeader req
    return { error : apiErrors.unauthorizedRequest }

  return { error : null, token, username, email, firstName, lastName }

