diff --git a/lernplattform/__init__.py b/lernplattform/__init__.py index efea60a..61d0497 100644 --- a/lernplattform/__init__.py +++ b/lernplattform/__init__.py @@ -1,9 +1,22 @@ from flask import Flask from flask_sqlalchemy import SQLAlchemy +# Initialize a new Flask app instance with the name of the current module (main). app = Flask(__name__) + +# Set the secret key for this application. This is required for session management in Flask. +# The secret key should be a cryptographically secure random value, and it's used to sign cookies. +# For more information: https://flask.palletsprojects.com/en/2.3.x/config/#SECRET_KEY +app.secret_key = 'faab0674dd8d9a4554cbeb53da2dad1414cc4c64b778e282da0b1662df7e0f85' + +# Configure the database URI for SQLAlchemy. Here, it uses an SQLite database named 'learn.db'. app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///learn.db' + +# Disable tracking modifications to the database, which is not necessary in this case and can improve performance. app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False + +# Initialize SQLAlchemy with the Flask app instance for database management. db = SQLAlchemy(app) +# Import the routes module from the lernplattform package, which is assumed to be in the same directory. import lernplattform.routes \ No newline at end of file diff --git a/lernplattform/classes.py b/lernplattform/classes.py index c89c380..ce0c17d 100644 --- a/lernplattform/classes.py +++ b/lernplattform/classes.py @@ -1,4 +1,4 @@ -from flask import Flask, request +from flask import Flask, request, session from lernplattform import app from lernplattform.models import User @@ -17,11 +17,16 @@ class login(): def __init__(self, user_name=None): self.user_name = user_name # Initialize the user name attribute for the login class - @staticmethod def check(user_name): if user_name is None: + session['logged_in'] = False + session['user_name'] = 'Gast' return False # Return False if the user name is not provided else: + session['logged_in'] = True + session['user_name'] = user_name + return True # Otherwise, return True indicating a valid user name + def login(self): print("Login") # Print "Login" to indicate that the login method has been called diff --git a/lernplattform/routes.py b/lernplattform/routes.py index f35096b..a27c063 100644 --- a/lernplattform/routes.py +++ b/lernplattform/routes.py @@ -1,4 +1,4 @@ -from flask import render_template, url_for, flash, redirect, jsonify, request +from flask import render_template, url_for, flash, redirect, jsonify, request, session from lernplattform import app from lernplattform.models import User @@ -16,14 +16,10 @@ def index(): Returns: A rendered HTML template with the current username. """ - if login.check(request.cookies.get('user_name')): - user_name = User.query.filter_by(username=request.cookies.get('user_name')).first().username - else: - # If not logged in, default to 'Gast' - user_name = 'Gast' + login.check(request.cookies.get('user_name')) # Render the main page with the current username - return render_template('index.html', user_name=user_name) + return render_template('index.html', user_name=session['user_name']) @app.route('/users', methods=['GET']) def get_users(): diff --git a/lernplattform/templates/index.html b/lernplattform/templates/index.html index 312ac37..607e547 100644 --- a/lernplattform/templates/index.html +++ b/lernplattform/templates/index.html @@ -18,10 +18,11 @@ } body { color: #ffffff; + background-color: var(--background-color); } .light { - color: #888888; - font-weight: 100; + color: #cdcdcd; + font-weight: 400; font-size: small; } .sidebar { @@ -72,7 +73,7 @@ background-color: var(--nav-background-color); padding: 0; } - .navbar-nav .nav-link { + .navbar-nav .nav-link { color: var(--link-default-color) } @@ -83,6 +84,14 @@ .navbar-nav .nav-link.active { color: var(--link-active-color); } + + a { + color: #ffcc00; + } + a:hover { + color: #c07427; + } + .logo { display:inline; width: 50px; @@ -95,10 +104,6 @@ padding: 0; box-shadow: 0 -4px 8px rgba(0, 0, 0, 0.3); } - - body { - background-color: var(--background-color); - }
@@ -110,6 +115,34 @@