Improve the frontend modals
This commit is contained in:
@@ -86,12 +86,12 @@ class DataExportService:
|
||||
|
||||
active_sessions = []
|
||||
for token in tokens:
|
||||
if token.expires_at > datetime.now(timezone.utc) and not token.revoked:
|
||||
if token.expires_at > datetime.now(timezone.utc) and not token.is_revoked:
|
||||
active_sessions.append({
|
||||
"token_id": str(token.id),
|
||||
"created_at": token.created_at.isoformat() if token.created_at else None,
|
||||
"expires_at": token.expires_at.isoformat() if token.expires_at else None,
|
||||
"device_info": token.device_info
|
||||
"is_revoked": token.is_revoked
|
||||
})
|
||||
|
||||
return {
|
||||
@@ -118,9 +118,22 @@ class DataExportService:
|
||||
|
||||
async def _export_security_data(self, user_id: UUID) -> Dict[str, Any]:
|
||||
"""Export security-related data"""
|
||||
# First get user email
|
||||
user_query = select(User).where(User.id == user_id)
|
||||
user_result = await self.db.execute(user_query)
|
||||
user = user_result.scalar_one_or_none()
|
||||
|
||||
if not user:
|
||||
return {
|
||||
"recent_login_attempts": [],
|
||||
"total_attempts_exported": 0,
|
||||
"note": "User not found"
|
||||
}
|
||||
|
||||
# LoginAttempt uses email, not user_id
|
||||
query = select(LoginAttempt).where(
|
||||
LoginAttempt.user_id == user_id
|
||||
).order_by(LoginAttempt.attempted_at.desc()).limit(50)
|
||||
LoginAttempt.email == user.email
|
||||
).order_by(LoginAttempt.created_at.desc()).limit(50)
|
||||
|
||||
result = await self.db.execute(query)
|
||||
attempts = result.scalars().all()
|
||||
@@ -128,7 +141,7 @@ class DataExportService:
|
||||
login_attempts = []
|
||||
for attempt in attempts:
|
||||
login_attempts.append({
|
||||
"attempted_at": attempt.attempted_at.isoformat() if attempt.attempted_at else None,
|
||||
"attempted_at": attempt.created_at.isoformat() if attempt.created_at else None,
|
||||
"success": attempt.success,
|
||||
"ip_address": attempt.ip_address,
|
||||
"user_agent": attempt.user_agent,
|
||||
|
||||
@@ -463,7 +463,7 @@ class EnhancedUserService:
|
||||
return {"error": "User not found"}
|
||||
|
||||
# Get token activity
|
||||
active_tokens = await token_repo.get_user_active_tokens(user_id)
|
||||
active_tokens = await token_repo.get_active_tokens_for_user(user_id)
|
||||
|
||||
return {
|
||||
"user_id": user_id,
|
||||
@@ -483,4 +483,4 @@ class EnhancedUserService:
|
||||
|
||||
|
||||
# Legacy compatibility - alias EnhancedUserService as UserService
|
||||
UserService = EnhancedUserService
|
||||
UserService = EnhancedUserService
|
||||
|
||||
Reference in New Issue
Block a user