How to use the sanic.response function in sanic

To help you get started, we’ve selected a few sanic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Gingernaut / microAuth / app / routes / email.py View on Github external
async def confirm_account(request, token):
    try:
        user = db.session.query(User).filter_by(UUID=token).first()

        if not user:
            return response.json({"error": "No user for given token"}, 400)

        user.isVerified = True
        db.session.commit()

        resp = user.serialize(jwt=True)
        resp["success"] = "User account confirmed"
        return response.json(resp, 200)

    except Exception as e:
        return utils.exeption_handler(e, "User confirmation failed", 500)
github steemit / jussi / jussi / handlers.py View on Github external
'tasks.count': len(tasks),
            'tasks': grouped_tasks
        }
    except Exception as e:
        logger.error('error adding cache info', e=e)
    data = {
        'source_commit': http_request.app.config.args.source_commit,
        'docker_tag': http_request.app.config.args.docker_tag,
        'jussi_num': http_request.app.config.last_irreversible_block_num,
        'asyncio': async_data,
        'cache': cache_data,
        'server': server_data,
        'ws_pools': ws_pools

    }
    return response.json(data)
# pylint: enable=protected-access, too-many-locals, no-member, unused-variable
github botfront / rasa-for-botfront / rasa / core / channels / twilio.py View on Github external
async def health(_: Request) -> HTTPResponse:
            return response.json({"status": "ok"})
github hyperledger-labs / sawtooth-healthcare / rest_api / rest_api / workflow / contract.py View on Github external
async def get_all_contacts(request):
    """Fetches complete details of all Accounts in state"""
    LOGGER.debug("Call 'contract' request")
    client_key = general.get_request_key_header(request)
    contract_list = await security_messaging.get_contracts(request.app.config.VAL_CONN, client_key)
    contract_list_json = []
    for address, con in contract_list.items():
        contract_list_json.append({
            'client_pkey': con.client_pkey,
            'id': con.id,
            'name': con.name,
            'surname': con.surname
        })

    return response.json(body={'data': contract_list_json},
                         headers=general.get_response_headers())
github autogestion / pubgate / pubgate / api / v1 / user.py View on Github external
async def create_user(request):
    if request.app.config.OPEN_REGISTRATION:
        username = request.json["username"]
        if username:
            is_uniq = await User.is_unique(doc=dict(username=username))
            if is_uniq in (True, None):
                await User.insert_one(dict(username=username,
                                           password=request.json["password"],
                                           email=request.json["email"]))
                return response.json({'peremoga': 'yep'}, status=201)
            else:
                return response.json({'zrada': 'username n/a'})
    return response.json({'zrada': 'nope'})
github simonw / datasette / datasette / app.py View on Github external
def render(self, templates, **context):
        template = self.jinja_env.select_template(templates)
        select_templates = ['{}{}'.format(
            '*' if template_name == template.name else '',
            template_name
        ) for template_name in templates]
        return response.html(
            template.render({
                **context, **{
                    'app_css_hash': self.ds.app_css_hash(),
                    'select_templates': select_templates,
                }
github Gingernaut / microAuth / app / routes / users.py View on Github external
async def get(self, request):
        try:
            userId = utils.get_id_from_jwt(request)
            user = utils.get_account_by_id(userId)
            if not user:
                return response.json({"error": "User not found"}, 404)
            return response.json(user.serialize(), 200)

        except Exception as e:
            return utils.exeption_handler(e, "User not found", 400)
github its-a-feature / Apfell / apfell-docker / app / routes / reporting_routes.py View on Github external
async def ui_full_timeline(request, user):
    template = env.get_template('reporting_full_timeline.html')
    if use_ssl:
        content = template.render(links=await respect_pivot(links, request), name=user['username'], http="https", ws="wss", config=user['ui_config'])
    else:
        content = template.render(links=await respect_pivot(links, request), name=user['username'], http="http", ws="ws", config=user['ui_config'])
    return response.html(content)
github c0rvax / project-black / server / handlers / creds.py View on Github external
async def cb_get_creds(self, request, project_uuid):
        targets = request.json['targets']
        get_result = self.creds_manager.get_creds(targets=targets, project_uuid=project_uuid)

        return response.json(get_result)