Add login history to settings
This commit is contained in:
28
db.py
28
db.py
@@ -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)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user