mirror of
https://github.com/Fluffy-Bean/GameExpo23.git
synced 2025-05-21 10:34:52 +00:00
Move routes to own folder
This commit is contained in:
parent
7b86a6b6bb
commit
c1f8f67e64
9 changed files with 63 additions and 44 deletions
42
DV8-Expo/website/routes.py
Normal file
42
DV8-Expo/website/routes.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
from flask import Blueprint, render_template, redirect, flash
|
||||
from flask_login import login_user, logout_user, login_required
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField
|
||||
from wtforms.validators import DataRequired
|
||||
from website.models import Users
|
||||
|
||||
|
||||
blueprint = Blueprint("website", __name__)
|
||||
|
||||
|
||||
class LoginForm(FlaskForm):
|
||||
uuid = StringField(
|
||||
"uuid",
|
||||
validators=[DataRequired()],
|
||||
render_kw={"placeholder": "12345678-ABCD-ABCD-ABCD-123456789EFG"},
|
||||
)
|
||||
|
||||
|
||||
@blueprint.route("/")
|
||||
def index():
|
||||
return render_template("index.html")
|
||||
|
||||
|
||||
@blueprint.route("/login", methods=["GET", "POST"])
|
||||
def login():
|
||||
form = LoginForm()
|
||||
|
||||
if form.validate_on_submit():
|
||||
if user := Users.query.filter_by(uuid=str(form.uuid.data)).first():
|
||||
login_user(user, remember=True)
|
||||
return redirect("/")
|
||||
else:
|
||||
flash("Incorrect login")
|
||||
|
||||
return render_template("login.html", form=form)
|
||||
|
||||
@blueprint.route("/logout")
|
||||
@login_required
|
||||
def logout():
|
||||
logout_user()
|
||||
return redirect("/")
|
Loading…
Add table
Add a link
Reference in a new issue