fix auth misprint

This commit is contained in:
user 2024-08-11 16:15:02 +03:00
parent a074c86086
commit 40fd420b67
1 changed files with 4 additions and 4 deletions

View File

@ -52,12 +52,12 @@ async def s_api_v1_auth_twa(request):
wallet_info.account = Account.from_dict(auth_data['ton_proof']['account']) wallet_info.account = Account.from_dict(auth_data['ton_proof']['account'])
wallet_info.ton_proof = TonProof.from_dict({'proof': auth_data['ton_proof']['ton_proof']}) wallet_info.ton_proof = TonProof.from_dict({'proof': auth_data['ton_proof']['ton_proof']})
connection_payload = auth_data['ton_proof']['ton_proof']['payload'] connection_payload = auth_data['ton_proof']['ton_proof']['payload']
known_payload = (await request.ctx.db_session.execute(select(KnownKey).where(KnownKey.seed == connection_payload))).scalars().first() known_payload = (request.ctx.db_session.execute(select(KnownKey).where(KnownKey.seed == connection_payload))).scalars().first()
assert known_payload, "Unknown payload" assert known_payload, "Unknown payload"
assert known_payload.meta['I_user_id'] == known_user.id, "Invalid user_id" assert known_payload.meta['I_user_id'] == known_user.id, "Invalid user_id"
assert wallet_info.check_proof(connection_payload), "Invalid proof" assert wallet_info.check_proof(connection_payload), "Invalid proof"
for known_connection in (await request.ctx.db_session.execute(select(WalletConnection).where( for known_connection in (request.ctx.db_session.execute(select(WalletConnection).where(
and_( and_(
WalletConnection.user_id == known_user.id, WalletConnection.user_id == known_user.id,
WalletConnection.network == 'ton' WalletConnection.network == 'ton'
@ -65,7 +65,7 @@ async def s_api_v1_auth_twa(request):
))).scalars().all(): ))).scalars().all():
known_connection.invalidated = True known_connection.invalidated = True
for other_connection in (await request.ctx.db_session.execute(select(WalletConnection).where( for other_connection in (request.ctx.db_session.execute(select(WalletConnection).where(
WalletConnection.wallet_address == Address(wallet_info.account.address).to_string(1, 1, 1) WalletConnection.wallet_address == Address(wallet_info.account.address).to_string(1, 1, 1)
))).scalars().all(): ))).scalars().all():
other_connection.invalidated = True other_connection.invalidated = True
@ -86,7 +86,7 @@ async def s_api_v1_auth_twa(request):
without_pk=False without_pk=False
) )
request.ctx.db_session.add(new_connection) request.ctx.db_session.add(new_connection)
await request.ctx.db_session.commit() request.ctx.db_session.commit()
except BaseException as e: except BaseException as e:
make_log("auth", f"Invalid ton_proof: {e}", level="warning") make_log("auth", f"Invalid ton_proof: {e}", level="warning")
return response.json({"error": "Invalid ton_proof"}, status=400) return response.json({"error": "Invalid ton_proof"}, status=400)