diff --git "a/Icon\r" "b/Icon\r"
new file mode 100644
index 0000000..e69de29
diff --git a/lernplattform/classes.py b/lernplattform/classes.py
index ce0c17d..bde688a 100644
--- a/lernplattform/classes.py
+++ b/lernplattform/classes.py
@@ -1,6 +1,14 @@
-from flask import Flask, request, session
-from lernplattform import app
+from flask import Flask, request, session, make_response, redirect, url_for
+from werkzeug.security import generate_password_hash, check_password_hash
+from lernplattform import app, db
from lernplattform.models import User
+import random
+import string
+
+def generate_random_string(length=8):
+ characters = string.ascii_letters + string.digits
+ random_string = ''.join(random.choice(characters) for _ in range(length))
+ return random_string
class login():
"""
@@ -14,19 +22,61 @@ class login():
check(user_name): A static method that checks if the provided user name is valid.
login(self): Prints "Login" to indicate that the login method has been called.
"""
- def __init__(self, user_name=None):
+ def __init__(self, user_name=None, login_data=None):
self.user_name = user_name # Initialize the user name attribute for the login class
- def check(user_name):
- if user_name is None:
+ def check_logged_in():
+ if request.cookies.get('username') is None:
session['logged_in'] = False
- session['user_name'] = 'Gast'
+ session['username'] = 'Gast'
return False # Return False if the user name is not provided
else:
session['logged_in'] = True
- session['user_name'] = user_name
+ session['username'] = request.cookies.get('username')
+ session['userid'] = request.cookies.get('userid')
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
+
+ def login(login_data):
+ # get password from db
+ user = User.query.filter_by(username = login_data.get('username')).first()
+
+ if user and check_password_hash(user.password, login_data.get('password')):
+ if not user.email_check == "":
+ return False
+
+ session['userid'] = user.id
+ session['username'] = user.username
+ session['logged_in'] = True
+
+ if login_data['remember'] == 'on':
+ resp = make_response(redirect(url_for('index')))
+ resp.set_cookie('userid', user.id)
+ resp.set_cookie('username', user.username)
+
+ return True
+ else:
+ return False
+
+ def logout():
+ resp = make_response(redirect(url_for('index')))
+ resp.set_cookie('username', '', expires=0)
+ resp.set_cookie('userid', '', expires=0)
+ session['logged_in'] = False
+
+ return resp
+
+ def register(request):
+ username = request.form.get('username')
+ email = request.form.get('email')
+ password = request.form.get('password')
+ hashed_password = generate_password_hash(password, method='pbkdf2:sha256')
+
+ if User.query.filter_by(username = username).first():
+ return False # Return False if the user name is already in use
+ else:
+ random_string = generate_random_string()
+ user = User(username = username, email = email, password = hashed_password, email_check = random_string)
+ db.session.add(user)
+ db.session.commit()
+ return True
diff --git a/lernplattform/models.py b/lernplattform/models.py
index 7e5b684..48e7199 100644
--- a/lernplattform/models.py
+++ b/lernplattform/models.py
@@ -1,15 +1,28 @@
from lernplattform import db
+from sqlalchemy.sql import func
# Define a User model that represents the user table in the database
class User(db.Model):
- # Primary key column for the table, auto-incrementing integer
+ """
+ A class representing the user table in the database.
+
+ Attributes:
+ id (int): The unique identifier for each user, set as the primary key.
+ username (str): The username of the user, must be unique and cannot be null.
+ email (str): The email address of the user, must be unique and cannot be null.
+ password (str): The hashed password of the user, cannot be null.
+ email_check (str): A string field to store email verification status.
+ register_date (datetime): The date and time when the user registered, defaults to the current timestamp.
+
+ Methods:
+ __repr__(): Returns a string representation of the User object in the format "User('username', 'email')".
+ """
id = db.Column(db.Integer, primary_key=True)
- # Username column with a maximum length of 20 characters, unique and not nullable
username = db.Column(db.String(20), unique=True, nullable=False)
- # Email column with a maximum length of 120 characters, unique and not nullable
email = db.Column(db.String(120), unique=True, nullable=False)
- # Password column with a maximum length of 60 characters, not nullable
password = db.Column(db.String(60), nullable=False)
+ email_check = db.Column(db.String(10), nullable=True)
+ register_date = db.Column(db.DateTime, nullable=False, default=func.now())
# Magic method to represent the object as a string when printed or used in string context
def __repr__(self):
diff --git a/lernplattform/routes.py b/lernplattform/routes.py
index a27c063..c5b10fd 100644
--- a/lernplattform/routes.py
+++ b/lernplattform/routes.py
@@ -16,38 +16,38 @@ def index():
Returns:
A rendered HTML template with the current username.
"""
- login.check(request.cookies.get('user_name'))
+ login.check_logged_in()
# Render the main page with the current username
- return render_template('index.html', user_name=session['user_name'])
+ return render_template('index.html', page='index', user_name=session['username'])
-@app.route('/users', methods=['GET'])
-def get_users():
- # Query all users from the database
- users = User.query.all()
- # Create a list of dictionaries with user information
- user_list = [
- {
- "id": user.id,
- "username": user.username,
- "email": user.email,
- "password": user.password
- }
- for user in users
- ]
- # Return the list of users as a JSON response
- return jsonify(user_list)
- #return user_list[0]['username']
-@app.route('/users', methods=['POST'])
-def create_user():
- # Get the JSON data from the request body
- data = request.get_json()
- # Create a new User object with the provided username, email, and password
- new_user = User(username=data['username'], email=data['email'], password=data['password'])
- # Add the new user to the database session
- db.session.add(new_user)
- # Commit the transaction to save the new user in the database
- db.session.commit()
- # Return a success message with status code 201 (Created)
- return jsonify({'message': 'User created'}), 201
\ No newline at end of file
+@app.route('/login', methods=['GET', 'POST'])
+def userlogin():
+ if request.method == 'POST':
+ #data = request.form
+ if request.form.get('form_id') == 'login':
+ if login.login(request.form):
+ # get username, password, remember from form
+ flash('Login erfolgreich!', 'login')
+ return redirect(url_for('index'))
+ else:
+ flash('Ungültiger Benutzername, Passwort oder Registrierung noch nicht bestätigt.', 'login')
+
+ # Render the main page with the current username
+ return render_template('index.html', page='index', user_name=session['username'])
+
+
+@app.route('/register', methods=['GET', 'POST'])
+def register():
+ if request.method == 'POST':
+ if login.register(request):
+ flash('''
+ Du erhältst in den nächsten Minuten eine eMail mit einem Bestätigungslink.
+ Bitte klicke auf diesen Link, um deine Registrierung abzuschließen.
+ ''', 'register')
+
+ return redirect(url_for('index'))
+
+
+ return render_template('index.html', page='register', user_name=session['username'])
diff --git a/lernplattform/static/javascript.js b/lernplattform/static/javascript.js
new file mode 100644
index 0000000..d6d34e8
--- /dev/null
+++ b/lernplattform/static/javascript.js
@@ -0,0 +1,20 @@
+function validateForm() {
+ var username = document.forms["loginForm"]["username"].value;
+ var password = document.forms["loginForm"]["password"].value;
+ if (username == "" || password == "") {
+ alert("Benutzername und Passwort müssen ausgefüllt werden.");
+ return false;
+ }
+ return true;
+}
+
+function checkPasswords() {
+ var password = document.forms["registerForm"]["password"].value;
+ var confirmPassword = document.forms["registerForm"]["password_repeat"].value;
+
+ if (password != confirmPassword) {
+ alert("Passwörter stimmen nicht überein.");
+ return false;
+ }
+ return true;
+}
\ No newline at end of file
diff --git a/lernplattform/static/style.css b/lernplattform/static/style.css
new file mode 100644
index 0000000..e263bec
--- /dev/null
+++ b/lernplattform/static/style.css
@@ -0,0 +1,103 @@
+:root {
+ --primary-color: #102037; /* Definieren Sie die primäre Farbe */
+ --secondary-color: #f78b47; /* Definieren Sie die sekundäre Farbe */
+ --link-default-color: #ffffff; /* Definieren Sie die Link-Hover-Farbe */
+ --link-hover-color: #ffcc00; /* Definieren Sie die Link-Hover-Farbe */
+ --link-active-color: #ffcc00; /* Definieren Sie die Link-Hover-Farbe */
+ --background-color: #d4c4c4; /* Definieren Sie die Hintergrundfarbe */
+ --nav-background-color: #102037; /* Definieren Sie die Hintergrundfarbe */
+ --box-background-color: #102037;
+}
+body {
+ color: #ffffff;
+ background-color: var(--background-color);
+}
+.light {
+ color: #cdcdcd;
+ font-weight: 400;
+ font-size: small;
+}
+.sidebar {
+ height: 100%;
+ position: sticky;
+ top: 0;
+ background-color: var(--background-color);
+}
+.main-content {
+ background-color: var(--background-color);
+}
+.profile-card,
+.story,
+.post,
+.who-to-follow,
+.news {
+ background-color: var(--box-background-color);
+ padding: 20px;
+ border-radius: 15px;
+ margin-bottom: 20px;
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
+}
+.headbar {
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
+}
+.profile-card img,
+.who-to-follow img {
+ width: 60px;
+ height: 60px;
+ object-fit: cover;
+ border-radius: 50%;
+}
+.story input {
+ border-radius: 30px;
+}
+.story button {
+ border-radius: 20px;
+}
+.post img {
+ width: 100%;
+ border-radius: 15px;
+ margin-top: 10px;
+}
+.who-to-follow button {
+ border-radius: 20px;
+}
+.navbar {
+ background-color: var(--nav-background-color);
+ padding: 0;
+}
+.navbar-nav .nav-link {
+ color: var(--link-default-color)
+}
+
+.navbar-nav .nav-link:hover {
+ color: var(--link-hover-color);
+}
+
+.navbar-nav .nav-link.active {
+ color: var(--link-active-color);
+}
+
+a {
+ color: #ffcc00;
+}
+a:hover {
+ color: #c07427;
+}
+
+.logo {
+ display:inline;
+ width: 50px;
+ margin: 0;
+ padding: 0;
+}
+
+.footer {
+ background-color: var(--nav-background-color);
+ padding: 0;
+ box-shadow: 0 -4px 8px rgba(0, 0, 0, 0.3);
+}
+
+.errormsg {
+ color: red;
+ font-size: 15px;
+}
\ No newline at end of file
diff --git a/lernplattform/templates/block_content_index.html b/lernplattform/templates/block_content_index.html
new file mode 100644
index 0000000..e275e68
--- /dev/null
+++ b/lernplattform/templates/block_content_index.html
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
+
+
Lernplattform für Rettungs- und Notfallsanitäter
+
+ 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.
+ 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.
+
+
+
+
+
+ I'm thrilled to share that I've completed a graduate certificate course in project
+ management with the president's honor roll.
+
+
+
\ No newline at end of file
diff --git a/lernplattform/templates/block_lernfelder.html b/lernplattform/templates/block_lernfelder.html
new file mode 100644
index 0000000..d895d3f
--- /dev/null
+++ b/lernplattform/templates/block_lernfelder.html
@@ -0,0 +1,39 @@
+
+
Lernfelder
+
+
+
+
Anatomie
+ RettSan
+
+
+
+
+
+
+
Medikamente
+ NotSan
+
+
+
+
+
+
+
Herzkreislauf
+ RettSan
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/lernplattform/templates/block_login.html b/lernplattform/templates/block_login.html
new file mode 100644
index 0000000..517ea7d
--- /dev/null
+++ b/lernplattform/templates/block_login.html
@@ -0,0 +1,54 @@
+
+{% if not session['logged_in'] %}
+
I'd love to change the world, but they won’t give me the source code.
+
+ 256 Posts
+ 2.5K Followers
+ 365 Following
+
+{% endif %}
+
\ No newline at end of file
diff --git a/lernplattform/templates/block_register.html b/lernplattform/templates/block_register.html
new file mode 100644
index 0000000..d60bfbb
--- /dev/null
+++ b/lernplattform/templates/block_register.html
@@ -0,0 +1,28 @@
+
+
+
Registrierung
+
Registriere dich, um die Plattform zu nutzen. Deine Daten werden nicht an Dritte weitergegeben oder anderweitig anderweitig
+ verarbeitet. Die dienen lediglich zur Authentifizierung und Speicherung deines Lernfortschrittes.
+
+
+
\ No newline at end of file
diff --git a/lernplattform/templates/index.html b/lernplattform/templates/index.html
index 607e547..ab1bf3a 100644
--- a/lernplattform/templates/index.html
+++ b/lernplattform/templates/index.html
@@ -5,106 +5,8 @@
Lernplattform EMT/Paramedic
-
+
+
@@ -116,44 +18,7 @@
I'd love to change the world, but they won’t give me the source code.
-
- 256 Posts
- 2.5K Followers
- 365 Following
-
- {% endif %}
-
+ {% include 'block_login.html' %}
-
-
+ {% if not page or page == '' or page == 'index' %}
+ {% include 'block_content_index.html' %}
+ {% elif page == 'register' %}
+ {% include 'block_register.html' %}
+ {% endif %}
-
-
-
-
-
-
-
Lernplattform für Rettungs- und Notfallsanitäter
-
- 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.
- 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.
-
-
-
-
-
- I'm thrilled to share that I've completed a graduate certificate course in project
- management with the president's honor roll.
-