def newaccount(environ, start_response):
    """ create new account """
    if environ['REQUEST_METHOD'] == 'POST':

        account = Account(DEBUG, get_url(environ), LOGGER)
        request_body = get_request_body(environ)
        response_dic = account.new(request_body)

        # create header
        headers = create_header(response_dic)
        start_response(
            '{0} {1}'.format(response_dic['code'],
                             HTTP_CODE_DIC[response_dic['code']]), headers)

        # logging
        logger_info(LOGGER, environ['REMOTE_ADDR'], environ['PATH_INFO'],
                    response_dic)
        return [json.dumps(response_dic['data']).encode('utf-8')]

    else:
        start_response('405 {0}'.format(HTTP_CODE_DIC[405]),
                       [('Content-Type', 'application/json')])
        return [
            json.dumps({
                'status': 405,
                'message': HTTP_CODE_DIC[405],
                'detail': 'Wrong request type. Expected POST.'
            }).encode('utf-8')
        ]
Esempio n. 2
0
def newaccount(request):
    """ new account """
    if request.method == 'POST':
        with Account(DEBUG, get_url(request.META), LOGGER) as account:
            response_dic = account.new(request.body)
            # create the response
            response = JsonResponse(status=response_dic['code'],
                                    data=response_dic['data'])

            # generate additional header elements
            for element in response_dic['header']:
                response[element] = response_dic['header'][element]

            # logging
            logger_info(LOGGER, request.META['REMOTE_ADDR'],
                        request.META['PATH_INFO'], response_dic)
            # send response
            return response
    else:
        return JsonResponse(status=405,
                            data={
                                'status': 405,
                                'message': 'Method Not Allowed',
                                'detail': 'Wrong request type. Expected POST.'
                            })
def acct(environ, start_response):
    """ account handling """
    with Account(DEBUG, get_url(environ), LOGGER) as account:
        request_body = get_request_body(environ)
        response_dic = account.parse(request_body)

        # create header
        headers = create_header(response_dic)
        start_response('{0} {1}'.format(response_dic['code'], HTTP_CODE_DIC[response_dic['code']]), headers)
        return [json.dumps(response_dic['data']).encode('utf-8')]
Esempio n. 4
0
def acct(request):
    """ xxxx command """
    with Account(DEBUG, get_url(request.META), LOGGER) as account:
        response_dic = account.parse(request.body)
        # create the response
        response = JsonResponse(status=response_dic['code'],
                                data=response_dic['data'])

        # generate additional header elements
        for element in response_dic['header']:
            response[element] = response_dic['header'][element]

        # logging
        logger_info(LOGGER, request.META['REMOTE_ADDR'],
                    request.META['PATH_INFO'], response_dic)
        # send response
        return response