Credential update was being done out of transaction, now part of login.

This commit is contained in:
Leo Vasanko
2026-01-28 02:22:47 +00:00
parent f29bd98020
commit ed8de169de
3 changed files with 13 additions and 9 deletions
+7 -6
View File
@@ -707,7 +707,8 @@ def _create_token() -> str:
def login(
user_uuid: UUID,
credential: Credential,
credential_uuid: UUID,
sign_count: int,
host: str,
ip: str,
user_agent: str,
@@ -728,8 +729,8 @@ def login(
now = datetime.now(timezone.utc)
if user_uuid not in _db.users:
raise ValueError(f"User {user_uuid} not found")
if credential.uuid not in _db.credentials:
raise ValueError(f"Credential {credential.uuid} not found")
if credential_uuid not in _db.credentials:
raise ValueError(f"Credential {credential_uuid} not found")
session_key = _create_token()
user_str = str(user_uuid)
@@ -738,12 +739,12 @@ def login(
_db.users[user_uuid].last_seen = now
_db.users[user_uuid].visits += 1
# Update credential
_db.credentials[credential.uuid].sign_count = credential.sign_count
_db.credentials[credential.uuid].last_used = now
_db.credentials[credential_uuid].sign_count = sign_count
_db.credentials[credential_uuid].last_used = now
# Create session
_db.sessions[session_key] = Session(
user=user_uuid,
credential=credential.uuid,
credential=credential_uuid,
host=host,
ip=ip,
user_agent=user_agent,
+4 -2
View File
@@ -334,7 +334,8 @@ async def websocket_remote_auth_permit(ws: WebSocket):
normalized_host = hostutil.normalize_host(request.host)
session_token = db.login(
user_uuid=cred.user,
credential=cred,
credential_uuid=cred.uuid,
sign_count=cred.sign_count,
host=normalized_host,
ip=request.ip,
user_agent=request.user_agent,
@@ -346,7 +347,8 @@ async def websocket_remote_auth_permit(ws: WebSocket):
normalized_host = hostutil.normalize_host(request.host)
session_token = db.login(
user_uuid=cred.user,
credential=cred,
credential_uuid=cred.uuid,
sign_count=cred.sign_count,
host=normalized_host,
ip=request.ip,
user_agent=request.user_agent,
+2 -1
View File
@@ -115,7 +115,8 @@ async def websocket_authenticate(ws: WebSocket, auth=AUTH_COOKIE):
token = db.login(
user_uuid=cred.user,
credential=cred,
credential_uuid=cred.uuid,
sign_count=cred.sign_count,
host=normalized_host,
ip=metadata["ip"],
user_agent=metadata["user_agent"],