2024-08-06 20:11:36 +02:00
|
|
|
from flask import render_template, url_for, flash, redirect, jsonify, request, session
|
2024-08-05 20:43:29 +02:00
|
|
|
from lernplattform import app
|
|
|
|
from lernplattform.models import User
|
|
|
|
|
2024-08-06 19:06:09 +02:00
|
|
|
from lernplattform import db
|
|
|
|
from lernplattform.classes import login
|
|
|
|
|
2024-08-05 20:43:29 +02:00
|
|
|
@app.route('/')
|
|
|
|
def index():
|
2024-08-06 19:06:09 +02:00
|
|
|
"""
|
|
|
|
Renders the main page of the application.
|
|
|
|
This function checks if a user is logged in by checking for a 'user_name' cookie.
|
|
|
|
If the user is logged in, it retrieves the username from the database using the cookie value.
|
|
|
|
If not, it defaults to 'Gast'. The main page is then rendered with the current username.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A rendered HTML template with the current username.
|
|
|
|
"""
|
2024-08-08 11:55:21 +02:00
|
|
|
login.check_logged_in()
|
2024-08-06 19:06:09 +02:00
|
|
|
|
|
|
|
# Render the main page with the current username
|
2024-08-08 11:55:21 +02:00
|
|
|
return render_template('index.html', page='index', user_name=session['username'])
|
|
|
|
|
|
|
|
|
|
|
|
@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'])
|