diff --git a/website/__pycache__/app.cpython-311.pyc b/website/__pycache__/app.cpython-311.pyc index c43e69d..b132526 100644 Binary files a/website/__pycache__/app.cpython-311.pyc and b/website/__pycache__/app.cpython-311.pyc differ diff --git a/website/__pycache__/init_db.cpython-311.pyc b/website/__pycache__/init_db.cpython-311.pyc index b660905..212cb48 100644 Binary files a/website/__pycache__/init_db.cpython-311.pyc and b/website/__pycache__/init_db.cpython-311.pyc differ diff --git a/website/app.py b/website/app.py index 5ee97eb..1e657f2 100755 --- a/website/app.py +++ b/website/app.py @@ -15,7 +15,7 @@ from wtforms.validators import DataRequired, Email, Length, EqualTo, ValidationE from functools import wraps import secrets from sqlalchemy.sql import func -import openai +from openai import OpenAI from dotenv import load_dotenv # Modelle importieren @@ -26,7 +26,7 @@ from models import ( ) # Lade .env-Datei -load_dotenv(force=True) # force=True erzwingt die Synchronisierung +load_dotenv() # force=True erzwingt die Synchronisierung # Bestimme den absoluten Pfad zur Datenbank basedir = os.path.abspath(os.path.dirname(__file__)) @@ -41,7 +41,7 @@ app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=365) # Langlebige Session für Dark Mode-Einstellung # OpenAI API-Konfiguration -openai.api_key = os.environ.get('OPENAI_API_KEY') +client = OpenAI(api_key="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") # Context processor für globale Template-Variablen @app.context_processor @@ -931,11 +931,6 @@ def too_many_requests(e): @app.route('/api/assistant', methods=['POST']) def chat_with_assistant(): """Chatbot-API mit OpenAI Integration.""" - if not openai.api_key: - return jsonify({ - 'error': 'OpenAI API-Schlüssel fehlt. Bitte in .env-Datei konfigurieren.' - }), 500 - data = request.json prompt = data.get('prompt', '') context = data.get('context', '') @@ -956,17 +951,17 @@ def chat_with_assistant(): if context: system_message += f"\n\nKontext: {context}" - response = openai.ChatCompletion.create( - model="gpt-3.5-turbo", + response = client.chat.completions.create( + model="gpt-3.5-turbo-16k", messages=[ {"role": "system", "content": system_message}, {"role": "user", "content": prompt} ], - max_tokens=500, + max_tokens=300, temperature=0.7 ) - answer = response.choices[0].message.content.strip() + answer = response.choices[0].message.content return jsonify({ 'answer': answer @@ -1135,8 +1130,8 @@ def reload_env(): # Erzwinge das Neuladen der .env-Datei load_dotenv(override=True, force=True) - # Aktualisiere OpenAI API-Key - openai.api_key = os.environ.get('OPENAI_API_KEY') + # OpenAI API-Key ist bereits fest kodiert + # client wurde bereits mit festem API-Key initialisiert # Weitere Umgebungsvariablen hier aktualisieren, falls nötig app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', app.config['SECRET_KEY']) diff --git a/website/cookies.txt b/website/cookies.txt new file mode 100644 index 0000000..c31d989 --- /dev/null +++ b/website/cookies.txt @@ -0,0 +1,4 @@ +# Netscape HTTP Cookie File +# https://curl.se/docs/http-cookies.html +# This file was generated by libcurl! Edit at your own risk. + diff --git a/website/create_admin.py b/website/create_admin.py new file mode 100644 index 0000000..3de3c2d --- /dev/null +++ b/website/create_admin.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from app import app +from models import db, User +from datetime import datetime + +def create_admin_user(): + """Create an admin user in the database.""" + with app.app_context(): + try: + # Check if admin user already exists + admin = User.query.filter_by(username='admin').first() + if admin: + print("Admin user already exists") + return + + # Create admin user + admin = User( + username='admin', + email='admin@example.com', + is_admin=True, + created_at=datetime.utcnow() + ) + admin.set_password('admin') + + # Add and commit + db.session.add(admin) + db.session.commit() + + print("Admin user created successfully!") + + # Verify user was added + user = User.query.filter_by(username='admin').first() + if user: + print(f"Verified: Admin user exists with ID {user.id}") + else: + print("WARNING: Failed to verify admin user creation") + + except Exception as e: + print(f"Error creating admin user: {e}") + +if __name__ == "__main__": + create_admin_user() \ No newline at end of file diff --git a/website/database/systades.db b/website/database/systades.db index ee14153..eb737e2 100644 Binary files a/website/database/systades.db and b/website/database/systades.db differ diff --git a/website/database/systades.db.backup b/website/database/systades.db.backup new file mode 100644 index 0000000..1223cb7 Binary files /dev/null and b/website/database/systades.db.backup differ diff --git a/website/fix_db.py b/website/fix_db.py new file mode 100755 index 0000000..9bfbc93 --- /dev/null +++ b/website/fix_db.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import sqlite3 +from datetime import datetime +from app import app, db_path +from models import db + +def ensure_db_dir(): + """Make sure the database directory exists.""" + os.makedirs(os.path.dirname(db_path), exist_ok=True) + +def fix_database_schema(): + """Fix the database schema by adding missing columns.""" + with app.app_context(): + # Ensure directory exists + ensure_db_dir() + + # Check if database exists, create tables if needed + if not os.path.exists(db_path): + print("Database doesn't exist. Creating all tables from scratch...") + db.create_all() + print("Database tables created successfully!") + return + + # Connect to existing database + print(f"Connecting to database: {db_path}") + conn = sqlite3.connect(db_path) + cursor = conn.cursor() + + # Check if User table exists + cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='user'") + if not cursor.fetchone(): + print("User table doesn't exist. Creating all tables from scratch...") + conn.close() + db.create_all() + print("Database tables created successfully!") + return + + # Check existing columns + cursor.execute("PRAGMA table_info(user)") + columns = cursor.fetchall() + column_names = [col[1] for col in columns] + print("Existing columns in User table:", column_names) + + # Add missing columns + if 'created_at' not in column_names: + print("Adding 'created_at' column to User table...") + cursor.execute("ALTER TABLE user ADD COLUMN created_at TIMESTAMP") + + if 'last_login' not in column_names: + print("Adding 'last_login' column to User table...") + cursor.execute("ALTER TABLE user ADD COLUMN last_login TIMESTAMP") + + if 'avatar' not in column_names: + print("Adding 'avatar' column to User table...") + cursor.execute("ALTER TABLE user ADD COLUMN avatar VARCHAR(200)") + + if 'bio' not in column_names: + print("Adding 'bio' column to User table...") + cursor.execute("ALTER TABLE user ADD COLUMN bio TEXT") + + # Commit the changes + conn.commit() + conn.close() + print("Database schema updated successfully!") + +if __name__ == "__main__": + fix_database_schema() \ No newline at end of file diff --git a/website/rebuild_db.py b/website/rebuild_db.py new file mode 100644 index 0000000..159eb08 --- /dev/null +++ b/website/rebuild_db.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import sqlite3 +from datetime import datetime +from app import app, db_path, create_default_categories +from models import db, User, Category + +def rebuild_database(): + """Completely rebuilds the database by dropping and recreating all tables.""" + with app.app_context(): + print(f"Database path: {db_path}") + + # Back up existing database if it exists + if os.path.exists(db_path): + backup_path = db_path + '.backup' + try: + import shutil + shutil.copy2(db_path, backup_path) + print(f"Backed up existing database to {backup_path}") + except Exception as e: + print(f"Warning: Could not create backup - {str(e)}") + + # Ensure directory exists + os.makedirs(os.path.dirname(db_path), exist_ok=True) + + # Drop all tables and recreate them + print("Dropping all tables...") + db.drop_all() + + print("Creating all tables...") + db.create_all() + + # Create admin user + print("Creating admin user...") + admin = User( + username='admin', + email='admin@example.com', + is_admin=True, + created_at=datetime.utcnow() + ) + admin.set_password('admin') + db.session.add(admin) + + # Create regular user + print("Creating regular user...") + user = User( + username='user', + email='user@example.com', + is_admin=False, + created_at=datetime.utcnow() + ) + user.set_password('user') + db.session.add(user) + + try: + # Commit to generate user IDs + db.session.commit() + print("Users created successfully!") + + # Create default categories + print("Creating default categories...") + create_default_categories() + + print("Database rebuild completed successfully!") + except Exception as e: + db.session.rollback() + print(f"Error during database rebuild: {str(e)}") + raise + +if __name__ == "__main__": + rebuild_database() \ No newline at end of file diff --git a/website/templates/mindmap.html b/website/templates/mindmap.html index b1c3982..c06af0f 100644 --- a/website/templates/mindmap.html +++ b/website/templates/mindmap.html @@ -577,13 +577,38 @@
- -
+ + + + + + + + + + + + + + + + + + + + + + + + + +
-
-

Wissenslandschaft wird geladen...

-
-
+
+

Wissenslandschaft wird geladen...

+

Daten werden aus der Datenbank abgerufen

+
+
@@ -646,6 +671,33 @@
+ + +
{% endblock %} @@ -653,17 +705,20 @@ + + + + - - +