Add login history to settings

This commit is contained in:
Peter Stockings
2025-12-02 16:08:40 +11:00
parent ab7079f87e
commit 4227be5a80
7 changed files with 182 additions and 1 deletions

28
db.py
View File

@@ -547,4 +547,30 @@ ORDER BY invocation_time DESC""", [http_function_id])
return (True, f"Imported shared environment '{env_data['name']}'", result['id'])
except Exception as e:
return (False, f"Error importing environment '{env_data.get('name', 'unknown')}': {str(e)}", None)
return (False, f"Error importing environment '{env_data.get('name', 'unknown')}': {str(e)}", None)
def record_login(self, user_id, ip_address, user_agent, success=True, failure_reason=None):
"""Record a login attempt"""
try:
self.execute(
"""INSERT INTO login_history
(user_id, ip_address, user_agent, success, failure_reason)
VALUES (%s, %s, %s, %s, %s)""",
(user_id, ip_address, user_agent, success, failure_reason),
commit=True
)
return True
except Exception as e:
print(f"Error recording login: {e}")
return False
def get_login_history(self, user_id, limit=50):
"""Get login history for a user"""
return self.execute(
"""SELECT id, login_time, ip_address, user_agent, success, failure_reason
FROM login_history
WHERE user_id = %s
ORDER BY login_time DESC
LIMIT %s""",
(user_id, limit)
)