mirror of
https://github.com/Fluffy-Bean/GameExpo23.git
synced 2025-05-19 01:44:51 +00:00
Fuck so much to comment on
Renamed the folders and containers to something more reasonable Using .env file for secretes so I can better hide them from git Mostly it, I think
This commit is contained in:
parent
a29f06dfee
commit
a4ebfa8552
61 changed files with 84 additions and 111 deletions
66
GameExpo/website/routes.py
Normal file
66
GameExpo/website/routes.py
Normal file
|
@ -0,0 +1,66 @@
|
|||
from flask import Blueprint, render_template, redirect, flash, abort
|
||||
from flask_login import login_user, logout_user, login_required, current_user
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField
|
||||
from wtforms.validators import DataRequired
|
||||
from website.models import Users, Games
|
||||
|
||||
|
||||
blueprint = Blueprint("website", __name__)
|
||||
|
||||
|
||||
class LoginForm(FlaskForm):
|
||||
uuid = StringField(
|
||||
"uuid",
|
||||
validators=[DataRequired()],
|
||||
render_kw={"placeholder": "12345678-ABCD-ABCD-ABCD-123456789EFG"},
|
||||
)
|
||||
|
||||
|
||||
@blueprint.route("/")
|
||||
def index():
|
||||
games = Games.query.filter_by(approved=True).filter_by(visible=True).all()
|
||||
return render_template("index.html", games=games)
|
||||
|
||||
|
||||
@blueprint.route("/g/<int:game_id>")
|
||||
def g(game_id):
|
||||
game = (
|
||||
Games.query.filter_by(id=game_id)
|
||||
.filter_by(approved=True)
|
||||
.filter_by(visible=True)
|
||||
.first()
|
||||
)
|
||||
|
||||
if not game:
|
||||
abort(404)
|
||||
|
||||
return render_template("game.html", game=game)
|
||||
|
||||
|
||||
@blueprint.route("/editor")
|
||||
@login_required
|
||||
def editor():
|
||||
game = Users.query.filter_by(id=current_user.id).first().game
|
||||
return render_template("editor.html", game=game)
|
||||
|
||||
|
||||
@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