コード例 #1
0
async def update_account_info(request):
    """Updates auth information for the authorized account"""
    token = common.deserialize_auth_token(
        request.app.config.SECRET_KEY, request.token)

    update = {}
    if request.json.get('password'):
        update['hashed_password'] = bcrypt.hashpw(
            bytes(request.json.get('password'), 'utf-8'), bcrypt.gensalt())
    if request.json.get('email'):
        update['email'] = request.json.get('email')

    if update:
        updated_auth_info = await auth_query.update_auth_info(
            request.app.config.DB_CONN,
            token.get('email'),
            token.get('public_key'),
            update)
        new_token = common.generate_auth_token(
            request.app.config.SECRET_KEY,
            updated_auth_info.get('email'),
            updated_auth_info.get('publicKey'))
    else:
        updated_auth_info = await accounts_query.fetch_account_resource(
            request.app.config.DB_CONN,
            token.get('public_key'),
            token.get('public_key'))
        new_token = request.token

    return response.json(
        {
            'authorization': new_token,
            'account': updated_auth_info
        })
コード例 #2
0
async def update_account_info(request):
    """Updates auth information for the authorized account"""
    token = common.deserialize_auth_token(request.app.config.SECRET_KEY,
                                          request.token)

    update = {}
    if request.json.get('password'):
        update['hashed_password'] = bcrypt.hashpw(
            bytes(request.json.get('password'), 'utf-8'), bcrypt.gensalt())
    if request.json.get('email'):
        update['email'] = request.json.get('email')

    if update:
        updated_auth_info = await auth_query.update_auth_info(
            request.app.config.DB_CONN, token.get('email'),
            token.get('public_key'), update)
        new_token = common.generate_auth_token(
            request.app.config.SECRET_KEY, updated_auth_info.get('email'),
            updated_auth_info.get('publicKey'))
    else:
        updated_auth_info = await accounts_query.fetch_account_resource(
            request.app.config.DB_CONN, token.get('public_key'),
            token.get('public_key'))
        new_token = request.token

    return response.json({
        'authorization': new_token,
        'account': updated_auth_info
    })
コード例 #3
0
async def get_account(request, key):
    """Fetches the details of particular Account in state"""
    try:
        auth_key = common.deserialize_auth_token(
            request.app.config.SECRET_KEY, request.token).get('public_key')
    except (BadSignature, TypeError):
        auth_key = None
    account_resource = await accounts_query.fetch_account_resource(
        request.app.config.DB_CONN, key, auth_key)
    return response.json(account_resource)
コード例 #4
0
async def get_account(request, key):
    """Fetches the details of particular Account in state"""
    try:
        auth_key = common.deserialize_auth_token(
            request.app.config.SECRET_KEY,
            request.token).get('public_key')
    except (BadSignature, TypeError):
        auth_key = None
    account_resource = await accounts_query.fetch_account_resource(
        request.app.config.DB_CONN, key, auth_key)
    return response.json(account_resource)
コード例 #5
0
 async def decorated_function(request, *args, **kwargs):
     if request.token is None:
         raise ApiUnauthorized("No bearer token provided")
     try:
         email = common.deserialize_auth_token(
             request.app.config.SECRET_KEY, request.token).get('email')
         auth_info = await auth_query.fetch_info_by_email(
             request.app.config.DB_CONN, email)
         if auth_info is None:
             raise ApiUnauthorized(
                 "Token does not belong to an existing user")
     except BadSignature:
         raise ApiUnauthorized("Invalid bearer token")
     response = await func(request, *args, **kwargs)
     return response
コード例 #6
0
 async def decorated_function(request, *args, **kwargs):
     if request.token is None:
         raise ApiUnauthorized("No bearer token provided")
     try:
         email = common.deserialize_auth_token(
             request.app.config.SECRET_KEY,
             request.token).get('email')
         auth_info = await auth_query.fetch_info_by_email(
             request.app.config.DB_CONN, email)
         if auth_info is None:
             raise ApiUnauthorized(
                 "Token does not belong to an existing user")
     except BadSignature:
         raise ApiUnauthorized("Invalid bearer token")
     response = await func(request, *args, **kwargs)
     return response
コード例 #7
0
ファイル: accounts.py プロジェクト: NeelNetwork/Neel-Core
async def transfer_asset(request):
    """Updates auth information for the authorized account"""
    token = common.deserialize_auth_token(
        request.app.config.SECRET_KEY, request.token)

    signer = await common.get_signer(request)
    await asyncio.sleep(2.0)  # Mitigate race condition


    required_fields = ['targetID', 'assetName', 'amount']
    common.validate_fields(required_fields, request.json)


    targetID = request.json.get('targetID')
    assetName = request.json.get('assetName')
    amount = request.json.get('amount')


    return send_payment(request ,signer.get_public_key().as_hex(), targetID, assetName, amount)