logger = (require 'logging').default 'register'

# fftcg.db (persistent data)
fftcgdb = (require '../../db')

module.exports =
  url: '/user/register'
  method: 'POST'
  schema: (require './user.schema')

  handler: (request, reply) ->
    fftcgdb.register(request.body.login, request.body.password)
    .then (user) ->
      logger.info "OK '#{request.body.login}'"
      reply.send
        success: true
        user: user
      return

    .catch (err) ->
      logger.debug "FAIL '#{request.body.login}'"
      reply.send
        success: false
        err: err
