Linker Block je nach Login Status
This commit is contained in:
parent
751c67c05b
commit
41a1bb3530
@ -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
|
@ -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
|
||||
|
@ -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():
|
||||
|
@ -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);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@ -110,6 +115,34 @@
|
||||
<!-- Sidebar -->
|
||||
<div class="col-12 col-md-3 sidebar mb-3">
|
||||
<div class="profile-card text-center p-3">
|
||||
|
||||
<!-- wenn logged out -->
|
||||
{% if not session['logged_in'] %}
|
||||
<h5>{{ user_name }}</h5>
|
||||
<p>Login oder <a href="#">Registrieren</a></p>
|
||||
<p class="light">Warum registrieren? Zum Schutz der Daten und dem Speichern deines Lernfortschrittes.</p>
|
||||
|
||||
<form>
|
||||
<div class="row mb-3">
|
||||
<label for="inputEmail3" class="col-sm-3 col-form-label">Benutzer</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="email" class="form-control" id="inputEmail3">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-3">
|
||||
<label for="inputPassword3" class="col-sm-3 col-form-label">Password</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="password" class="form-control" id="inputPassword3">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Einloggen</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
<!-- wenn logged out -->
|
||||
|
||||
<!-- wenn logged in -->
|
||||
{% if session['logged_in'] %}
|
||||
<!--<img src="https://via.placeholder.com/100" alt="Profile Picture" />-->
|
||||
<h5>{{ user_name }}</h5>
|
||||
<p>Web Developer at Webestica</p>
|
||||
@ -119,6 +152,9 @@
|
||||
<span>2.5K Followers</span>
|
||||
<span>365 Following</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
<!-- wenn logged in -->
|
||||
|
||||
</div>
|
||||
<!--
|
||||
<div class="list-group">
|
||||
@ -162,11 +198,18 @@
|
||||
<img
|
||||
src="../static/images/logo.png"
|
||||
class="rounded-circle me-3"
|
||||
style="width: 300px;"
|
||||
style="width: 300px; height: 300px;"
|
||||
alt="Profile Picture" />
|
||||
<div>
|
||||
<div class="my-3">
|
||||
<h6>Lernplattform für <br>Rettungs- und Notfallsanitäter</h6>
|
||||
<small class="light">Hier kann man lernen und üben, Wiessen festigen und sich aktiv an der Datenbank beteiligen.</small>
|
||||
<p class="light" style="text-align: justify;">
|
||||
Willkommen auf unserer Lernplattform für Rettungssanitäter und Notfallsanitäter,
|
||||
basierend auf dem bewährten Kartensystem nach Leitner.
|
||||
Unsere Plattform bietet Dir die Möglichkeit,
|
||||
Deine Kenntnisse und Fähigkeiten effektiv zu vertiefen und zu erweitern. <br><br>
|
||||
Bei Interesse bist Du herzlich eingeladen, an der Entwicklung von Fragen und Aufgaben mitzuwirken.
|
||||
Unsere Plattform ist und bleibt kostenlos, um alle Mitarbeiter im Rettungsdienst bestmöglich zu unterstützen.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user