Add login history to settings
This commit is contained in:
@@ -41,13 +41,20 @@ def login():
|
||||
|
||||
user_data = db.get_user_by_username(username)
|
||||
if not user_data:
|
||||
# Record failed login attempt
|
||||
db.record_login(None, request.remote_addr, str(request.user_agent), False, "User not found")
|
||||
return render_template("login.html", error="User does not exist")
|
||||
|
||||
if not check_password_hash(user_data['password_hash'], password):
|
||||
# Record failed login attempt
|
||||
db.record_login(user_data['id'], request.remote_addr, str(request.user_agent), False, "Invalid password")
|
||||
return render_template("login.html", error="Invalid username or password")
|
||||
|
||||
user = User(id=str(user_data['id']), username=user_data['username'], password_hash=user_data['password_hash'], created_at=user_data['created_at'], theme_preference=user_data.get('theme_preference', 'light'))
|
||||
|
||||
# Record successful login
|
||||
db.record_login(user.id, request.remote_addr, str(request.user_agent), True)
|
||||
|
||||
login_user(user)
|
||||
|
||||
next = request.args.get('next')
|
||||
|
||||
@@ -133,6 +133,23 @@ def database_schema():
|
||||
)
|
||||
return render_template("dashboard/settings/database_schema.html", schema_info=schema_info)
|
||||
|
||||
@settings.route("/login-history", methods=["GET"])
|
||||
@login_required
|
||||
def login_history():
|
||||
"""Display login history for the current user"""
|
||||
user_id = current_user.id
|
||||
history = db.get_login_history(user_id, limit=50)
|
||||
|
||||
if htmx:
|
||||
return render_block(
|
||||
environment,
|
||||
"dashboard/settings/login_history.html",
|
||||
"page",
|
||||
history=history
|
||||
)
|
||||
return render_template("dashboard/settings/login_history.html", history=history)
|
||||
|
||||
|
||||
def get_database_schema():
|
||||
"""Fetch database schema information for ERD generation"""
|
||||
# Get all tables
|
||||
@@ -413,3 +430,4 @@ def import_data():
|
||||
|
||||
except Exception as e:
|
||||
return {"error": f"Import failed: {str(e)}"}, 500
|
||||
|
||||
|
||||
Reference in New Issue
Block a user