Compare commits
11 Commits
till-v2
...
fd7bc59851
| Author | SHA1 | Date | |
|---|---|---|---|
| fd7bc59851 | |||
| 55f1f87509 | |||
| 03f8761312 | |||
| 506748fda7 | |||
| 6d069f68cd | |||
| 4310239a7a | |||
| e9fe907af0 | |||
| 0c69d9aba3 | |||
| 6da85cdece | |||
| a073b09115 | |||
| f1f4870989 |
27
Dockerfile
27
Dockerfile
@@ -1,10 +1,27 @@
|
||||
FROM python:3.9-slim-buster
|
||||
FROM python:3.11-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt requirements.txt
|
||||
RUN pip install -r requirements.txt
|
||||
# System dependencies
|
||||
RUN apt-get update && apt-get install -y \
|
||||
gcc \
|
||||
python3-dev \
|
||||
libffi-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY website .
|
||||
# Clean up and install requirements
|
||||
RUN rm -rf /app/*
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt \
|
||||
&& pip install --no-cache-dir wheel setuptools
|
||||
|
||||
CMD ["python", "app.py"]
|
||||
# Copy application files
|
||||
COPY website/ ./website/
|
||||
COPY requirements.txt .
|
||||
|
||||
EXPOSE 6000
|
||||
|
||||
# Verify installations
|
||||
RUN pip list
|
||||
|
||||
CMD ["python", "website/app.py"]
|
||||
@@ -1,7 +1,16 @@
|
||||
version: "3.9"
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
web:
|
||||
build: .
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
ports:
|
||||
- "5000:5000"
|
||||
- "6000:6000"
|
||||
volumes:
|
||||
- ./website:/app/website
|
||||
environment:
|
||||
- FLASK_ENV=development
|
||||
- FLASK_DEBUG=1
|
||||
command: python website/app.py
|
||||
restart: always
|
||||
BIN
instance/mindmap.db
Normal file
BIN
instance/mindmap.db
Normal file
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
flask
|
||||
flask-login
|
||||
flask-wtf
|
||||
email-validator
|
||||
python-dotenv
|
||||
flask-sqlalchemy
|
||||
Flask
|
||||
Flask-Login
|
||||
Flask-SQLAlchemy
|
||||
Werkzeug
|
||||
SQLAlchemy
|
||||
email_validator
|
||||
72
start.sh
Normal file
72
start.sh
Normal file
@@ -0,0 +1,72 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Farben für die Ausgabe
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Funktion zum Anzeigen des Hilfetexts
|
||||
show_help() {
|
||||
echo -e "${YELLOW}Verwendung: ./start.sh [Option]${NC}"
|
||||
echo "Optionen:"
|
||||
echo " start - Startet die Container"
|
||||
echo " stop - Stoppt die Container"
|
||||
echo " restart - Neustart der Container"
|
||||
echo " rebuild - Baut die Container neu"
|
||||
echo " clean - Entfernt alle Container und Images"
|
||||
echo " logs - Zeigt die Container-Logs"
|
||||
echo " help - Zeigt diese Hilfe"
|
||||
}
|
||||
|
||||
# Prüfen ob Docker läuft
|
||||
check_docker() {
|
||||
if ! docker info > /dev/null 2>&1; then
|
||||
echo -e "${RED}Error: Docker ist nicht gestartet${NC}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
check_docker
|
||||
echo -e "${GREEN}Starte Container...${NC}"
|
||||
docker-compose up -d
|
||||
echo -e "${GREEN}Container erfolgreich gestartet!${NC}"
|
||||
;;
|
||||
stop)
|
||||
check_docker
|
||||
echo -e "${YELLOW}Stoppe Container...${NC}"
|
||||
docker-compose down
|
||||
echo -e "${GREEN}Container erfolgreich gestoppt!${NC}"
|
||||
;;
|
||||
restart)
|
||||
check_docker
|
||||
echo -e "${YELLOW}Neustart der Container...${NC}"
|
||||
docker-compose down
|
||||
docker-compose up -d
|
||||
echo -e "${GREEN}Container erfolgreich neugestartet!${NC}"
|
||||
;;
|
||||
rebuild)
|
||||
check_docker
|
||||
echo -e "${YELLOW}Baue Container neu...${NC}"
|
||||
docker-compose down --rmi all
|
||||
docker-compose build --no-cache
|
||||
docker-compose up -d
|
||||
echo -e "${GREEN}Container erfolgreich neu gebaut!${NC}"
|
||||
;;
|
||||
clean)
|
||||
check_docker
|
||||
echo -e "${RED}Entferne alle Container und Images...${NC}"
|
||||
docker-compose down --rmi all -v
|
||||
echo -e "${GREEN}Aufräumen abgeschlossen!${NC}"
|
||||
;;
|
||||
logs)
|
||||
check_docker
|
||||
echo -e "${YELLOW}Container-Logs:${NC}"
|
||||
docker-compose logs -f
|
||||
;;
|
||||
help|*)
|
||||
show_help
|
||||
;;
|
||||
esac
|
||||
434
website/app.py
434
website/app.py
@@ -6,15 +6,231 @@ from flask_sqlalchemy import SQLAlchemy
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
import json
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'default-dev-key')
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///mindmap.db'
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
|
||||
db = SQLAlchemy(app)
|
||||
login_manager = LoginManager(app)
|
||||
db = SQLAlchemy()
|
||||
login_manager = LoginManager()
|
||||
login_manager.login_view = 'login'
|
||||
|
||||
def create_app():
|
||||
app = Flask(__name__)
|
||||
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'default-dev-key')
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///mindmap.db'
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
|
||||
db.init_app(app)
|
||||
login_manager.init_app(app)
|
||||
|
||||
with app.app_context():
|
||||
# Initialize database and create root node
|
||||
db.create_all()
|
||||
try:
|
||||
root = MindMapNode.query.filter_by(parent_id=None).first()
|
||||
if not root:
|
||||
root = MindMapNode(name="Wissenschaft")
|
||||
db.session.add(root)
|
||||
db.session.commit()
|
||||
except Exception as e:
|
||||
print(f"Error initializing database: {str(e)}")
|
||||
|
||||
# Register all routes with the app
|
||||
@login_manager.user_loader
|
||||
def load_user(id):
|
||||
return User.query.get(int(id))
|
||||
|
||||
@app.route('/login', methods=['GET', 'POST'])
|
||||
def login():
|
||||
if request.method == 'POST':
|
||||
username = request.form.get('username')
|
||||
password = request.form.get('password')
|
||||
|
||||
user = User.query.filter_by(username=username).first()
|
||||
if user and user.check_password(password):
|
||||
login_user(user)
|
||||
next_page = request.args.get('next')
|
||||
return redirect(next_page or url_for('index'))
|
||||
flash('Ungültiger Benutzername oder Passwort')
|
||||
return render_template('login.html')
|
||||
|
||||
@app.route('/register', methods=['GET', 'POST'])
|
||||
def register():
|
||||
if request.method == 'POST':
|
||||
username = request.form.get('username')
|
||||
email = request.form.get('email')
|
||||
password = request.form.get('password')
|
||||
|
||||
if User.query.filter_by(username=username).first():
|
||||
flash('Benutzername existiert bereits')
|
||||
return redirect(url_for('register'))
|
||||
|
||||
if User.query.filter_by(email=email).first():
|
||||
flash('E-Mail ist bereits registriert')
|
||||
return redirect(url_for('register'))
|
||||
|
||||
user = User(username=username, email=email)
|
||||
user.set_password(password)
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
|
||||
login_user(user)
|
||||
return redirect(url_for('index'))
|
||||
return render_template('register.html')
|
||||
|
||||
@app.route('/logout')
|
||||
@login_required
|
||||
def logout():
|
||||
logout_user()
|
||||
return redirect(url_for('index'))
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
@app.route('/mindmap')
|
||||
def mindmap():
|
||||
try:
|
||||
root_node = MindMapNode.query.filter_by(parent_id=None).first()
|
||||
if not root_node:
|
||||
root_node = MindMapNode(name="Wissenschaft")
|
||||
db.session.add(root_node)
|
||||
db.session.commit()
|
||||
return render_template('mindmap.html')
|
||||
except Exception as e:
|
||||
app.logger.error(f"Error loading mindmap: {str(e)}")
|
||||
return render_template('mindmap.html', error="Fehler beim Laden der Mindmap. Bitte versuchen Sie es erneut.")
|
||||
|
||||
@app.route('/profile')
|
||||
@login_required
|
||||
def profile():
|
||||
thoughts = Thought.query.filter_by(user_id=current_user.id).order_by(Thought.timestamp.desc()).all()
|
||||
return render_template('profile.html', thoughts=thoughts)
|
||||
|
||||
@app.route('/api/mindmap')
|
||||
def get_mindmap():
|
||||
try:
|
||||
root_nodes = MindMapNode.query.filter_by(parent_id=None).all()
|
||||
|
||||
def build_tree(node):
|
||||
return {
|
||||
'id': node.id,
|
||||
'name': node.name,
|
||||
'children': [build_tree(child) for child in node.children]
|
||||
}
|
||||
|
||||
result = [build_tree(node) for node in root_nodes]
|
||||
if not result:
|
||||
root = MindMapNode(name="Wissenschaft")
|
||||
db.session.add(root)
|
||||
db.session.commit()
|
||||
result = [build_tree(root)]
|
||||
|
||||
return jsonify(result)
|
||||
except Exception as e:
|
||||
app.logger.error(f"Error in get_mindmap: {str(e)}")
|
||||
return jsonify({'error': 'Fehler beim Laden der Mindmap'}), 500
|
||||
|
||||
@app.route('/api/thoughts/<int:node_id>', methods=['GET'])
|
||||
def get_thoughts(node_id):
|
||||
node = MindMapNode.query.get_or_404(node_id)
|
||||
thoughts = []
|
||||
|
||||
for thought in node.thoughts:
|
||||
thoughts.append({
|
||||
'id': thought.id,
|
||||
'content': thought.content,
|
||||
'author': thought.author.username,
|
||||
'timestamp': thought.timestamp.strftime('%d.%m.%Y, %H:%M'),
|
||||
'comments_count': len(thought.comments),
|
||||
'branch': thought.branch
|
||||
})
|
||||
|
||||
return jsonify(thoughts)
|
||||
|
||||
@app.route('/api/thoughts', methods=['POST'])
|
||||
@login_required
|
||||
def add_thought():
|
||||
data = request.json
|
||||
node_id = data.get('node_id')
|
||||
content = data.get('content')
|
||||
|
||||
if not node_id or not content:
|
||||
return jsonify({'error': 'Fehlende Daten'}), 400
|
||||
|
||||
node = MindMapNode.query.get_or_404(node_id)
|
||||
|
||||
thought = Thought(
|
||||
content=content,
|
||||
branch=node.name,
|
||||
user_id=current_user.id
|
||||
)
|
||||
|
||||
db.session.add(thought)
|
||||
node.thoughts.append(thought)
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({
|
||||
'id': thought.id,
|
||||
'content': thought.content,
|
||||
'author': thought.author.username,
|
||||
'timestamp': thought.timestamp.strftime('%d.%m.%Y, %H:%M'),
|
||||
'branch': thought.branch
|
||||
})
|
||||
|
||||
@app.route('/api/comments/<int:thought_id>', methods=['GET'])
|
||||
def get_comments(thought_id):
|
||||
thought = Thought.query.get_or_404(thought_id)
|
||||
comments = [
|
||||
{
|
||||
'id': comment.id,
|
||||
'content': comment.content,
|
||||
'author': comment.author.username,
|
||||
'timestamp': comment.timestamp.strftime('%d.%m.%Y, %H:%M')
|
||||
}
|
||||
for comment in thought.comments
|
||||
]
|
||||
return jsonify(comments)
|
||||
|
||||
@app.route('/api/comments', methods=['POST'])
|
||||
@login_required
|
||||
def add_comment():
|
||||
data = request.json
|
||||
thought_id = data.get('thought_id')
|
||||
content = data.get('content')
|
||||
|
||||
if not thought_id or not content:
|
||||
return jsonify({'error': 'Fehlende Daten'}), 400
|
||||
|
||||
thought = Thought.query.get_or_404(thought_id)
|
||||
|
||||
comment = Comment(
|
||||
content=content,
|
||||
thought_id=thought_id,
|
||||
user_id=current_user.id
|
||||
)
|
||||
|
||||
db.session.add(comment)
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({
|
||||
'id': comment.id,
|
||||
'content': comment.content,
|
||||
'author': comment.author.username,
|
||||
'timestamp': comment.timestamp.strftime('%d.%m.%Y, %H:%M')
|
||||
})
|
||||
|
||||
@app.route('/admin')
|
||||
@login_required
|
||||
def admin():
|
||||
if not current_user.is_admin:
|
||||
flash('Zugriff verweigert')
|
||||
return redirect(url_for('index'))
|
||||
|
||||
users = User.query.all()
|
||||
nodes = MindMapNode.query.all()
|
||||
thoughts = Thought.query.all()
|
||||
|
||||
return render_template('admin.html', users=users, nodes=nodes, thoughts=thoughts)
|
||||
|
||||
return app
|
||||
|
||||
# Database Models
|
||||
class User(UserMixin, db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
@@ -59,206 +275,6 @@ node_thought_association = db.Table('node_thought_association',
|
||||
db.Column('thought_id', db.Integer, db.ForeignKey('thought.id'), primary_key=True)
|
||||
)
|
||||
|
||||
@login_manager.user_loader
|
||||
def load_user(id):
|
||||
return User.query.get(int(id))
|
||||
|
||||
# Routes for authentication
|
||||
@app.route('/login', methods=['GET', 'POST'])
|
||||
def login():
|
||||
if request.method == 'POST':
|
||||
username = request.form.get('username')
|
||||
password = request.form.get('password')
|
||||
|
||||
user = User.query.filter_by(username=username).first()
|
||||
if user and user.check_password(password):
|
||||
login_user(user)
|
||||
next_page = request.args.get('next')
|
||||
return redirect(next_page or url_for('index'))
|
||||
flash('Ungültiger Benutzername oder Passwort')
|
||||
return render_template('login.html')
|
||||
|
||||
@app.route('/register', methods=['GET', 'POST'])
|
||||
def register():
|
||||
if request.method == 'POST':
|
||||
username = request.form.get('username')
|
||||
email = request.form.get('email')
|
||||
password = request.form.get('password')
|
||||
|
||||
if User.query.filter_by(username=username).first():
|
||||
flash('Benutzername existiert bereits')
|
||||
return redirect(url_for('register'))
|
||||
|
||||
if User.query.filter_by(email=email).first():
|
||||
flash('E-Mail ist bereits registriert')
|
||||
return redirect(url_for('register'))
|
||||
|
||||
user = User(username=username, email=email)
|
||||
user.set_password(password)
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
|
||||
login_user(user)
|
||||
return redirect(url_for('index'))
|
||||
return render_template('register.html')
|
||||
|
||||
@app.route('/logout')
|
||||
@login_required
|
||||
def logout():
|
||||
logout_user()
|
||||
return redirect(url_for('index'))
|
||||
|
||||
# Route for the homepage
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
# Route for the mindmap page
|
||||
@app.route('/mindmap')
|
||||
def mindmap():
|
||||
return render_template('mindmap.html')
|
||||
|
||||
# Route for user profile
|
||||
@app.route('/profile')
|
||||
@login_required
|
||||
def profile():
|
||||
thoughts = Thought.query.filter_by(user_id=current_user.id).order_by(Thought.timestamp.desc()).all()
|
||||
return render_template('profile.html', thoughts=thoughts)
|
||||
|
||||
# API routes for mindmap and thoughts
|
||||
@app.route('/api/mindmap')
|
||||
def get_mindmap():
|
||||
root_nodes = MindMapNode.query.filter_by(parent_id=None).all()
|
||||
|
||||
def build_tree(node):
|
||||
return {
|
||||
'id': node.id,
|
||||
'name': node.name,
|
||||
'children': [build_tree(child) for child in node.children]
|
||||
}
|
||||
|
||||
result = [build_tree(node) for node in root_nodes]
|
||||
return jsonify(result)
|
||||
|
||||
@app.route('/api/thoughts/<int:node_id>', methods=['GET'])
|
||||
def get_thoughts(node_id):
|
||||
node = MindMapNode.query.get_or_404(node_id)
|
||||
thoughts = []
|
||||
|
||||
for thought in node.thoughts:
|
||||
thoughts.append({
|
||||
'id': thought.id,
|
||||
'content': thought.content,
|
||||
'author': thought.author.username,
|
||||
'timestamp': thought.timestamp.strftime('%d.%m.%Y, %H:%M'),
|
||||
'comments_count': len(thought.comments),
|
||||
'branch': thought.branch
|
||||
})
|
||||
|
||||
return jsonify(thoughts)
|
||||
|
||||
@app.route('/api/thought/<int:thought_id>', methods=['GET'])
|
||||
def get_thought(thought_id):
|
||||
thought = Thought.query.get_or_404(thought_id)
|
||||
|
||||
return jsonify({
|
||||
'id': thought.id,
|
||||
'content': thought.content,
|
||||
'author': thought.author.username,
|
||||
'timestamp': thought.timestamp.strftime('%d.%m.%Y, %H:%M'),
|
||||
'branch': thought.branch,
|
||||
'comments_count': len(thought.comments)
|
||||
})
|
||||
|
||||
@app.route('/api/thoughts', methods=['POST'])
|
||||
@login_required
|
||||
def add_thought():
|
||||
data = request.json
|
||||
node_id = data.get('node_id')
|
||||
content = data.get('content')
|
||||
|
||||
if not node_id or not content:
|
||||
return jsonify({'error': 'Fehlende Daten'}), 400
|
||||
|
||||
node = MindMapNode.query.get_or_404(node_id)
|
||||
|
||||
thought = Thought(
|
||||
content=content,
|
||||
branch=node.name,
|
||||
user_id=current_user.id
|
||||
)
|
||||
|
||||
db.session.add(thought)
|
||||
node.thoughts.append(thought)
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({
|
||||
'id': thought.id,
|
||||
'content': thought.content,
|
||||
'author': thought.author.username,
|
||||
'timestamp': thought.timestamp.strftime('%d.%m.%Y, %H:%M'),
|
||||
'branch': thought.branch
|
||||
})
|
||||
|
||||
@app.route('/api/comments/<int:thought_id>', methods=['GET'])
|
||||
def get_comments(thought_id):
|
||||
thought = Thought.query.get_or_404(thought_id)
|
||||
comments = [
|
||||
{
|
||||
'id': comment.id,
|
||||
'content': comment.content,
|
||||
'author': comment.author.username,
|
||||
'timestamp': comment.timestamp.strftime('%d.%m.%Y, %H:%M')
|
||||
}
|
||||
for comment in thought.comments
|
||||
]
|
||||
return jsonify(comments)
|
||||
|
||||
@app.route('/api/comments', methods=['POST'])
|
||||
@login_required
|
||||
def add_comment():
|
||||
data = request.json
|
||||
thought_id = data.get('thought_id')
|
||||
content = data.get('content')
|
||||
|
||||
if not thought_id or not content:
|
||||
return jsonify({'error': 'Fehlende Daten'}), 400
|
||||
|
||||
thought = Thought.query.get_or_404(thought_id)
|
||||
|
||||
comment = Comment(
|
||||
content=content,
|
||||
thought_id=thought_id,
|
||||
user_id=current_user.id
|
||||
)
|
||||
|
||||
db.session.add(comment)
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({
|
||||
'id': comment.id,
|
||||
'content': comment.content,
|
||||
'author': comment.author.username,
|
||||
'timestamp': comment.timestamp.strftime('%d.%m.%Y, %H:%M')
|
||||
})
|
||||
|
||||
# Admin routes
|
||||
@app.route('/admin')
|
||||
@login_required
|
||||
def admin():
|
||||
if not current_user.is_admin:
|
||||
flash('Zugriff verweigert')
|
||||
return redirect(url_for('index'))
|
||||
|
||||
users = User.query.all()
|
||||
nodes = MindMapNode.query.all()
|
||||
thoughts = Thought.query.all()
|
||||
|
||||
return render_template('admin.html', users=users, nodes=nodes, thoughts=thoughts)
|
||||
|
||||
# Flask starten
|
||||
if __name__ == '__main__':
|
||||
with app.app_context():
|
||||
# Make sure tables exist
|
||||
db.create_all()
|
||||
app.run(host="0.0.0.0", debug=True)
|
||||
app = create_app()
|
||||
app.run(host="0.0.0.0", port=6000, debug=True)
|
||||
Reference in New Issue
Block a user