54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
from flask import render_template, url_for, flash, redirect, jsonify, request, session
|
|
from lernplattform import app
|
|
from lernplattform.models import User
|
|
|
|
from lernplattform import db
|
|
from lernplattform.classes import login
|
|
|
|
@app.route('/')
|
|
def index():
|
|
"""
|
|
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.
|
|
"""
|
|
login.check_logged_in()
|
|
|
|
# Render the main page with the current username
|
|
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'])
|