Skip to content

Commit

Permalink
Update routes.py
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-sorrentino committed Jan 6, 2025
1 parent 7bb7588 commit 12fe30c
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions hushline/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def set_message_status(id: int) -> Response:
return redirect(url_for("message", id=id))

@app.route("/register", methods=["GET", "POST"])
def register() -> Response | str | tuple[Response | str, int]:
def register() -> Response | str:
if (
session.get("is_authenticated", False)
and (user_id := session.get("user_id", False))
Expand All @@ -434,7 +434,8 @@ def register() -> Response | str | tuple[Response | str, int]:

if form.validate_on_submit():
captcha_answer = request.form.get("captcha_answer", "")
if not validate_captcha(captcha_answer):
if captcha_answer != session.get("math_answer"):
flash("Incorrect CAPTCHA. Please try again.", "error")
return render_template(
"register.html",
form=form,
Expand All @@ -454,28 +455,22 @@ def register() -> Response | str | tuple[Response | str, int]:
tzinfo=UTC
) < datetime.now(UTC):
flash("⛔️ Invalid or expired invite code.", "error")
return (
render_template(
"register.html",
form=form,
require_invite_code=require_invite_code,
math_problem=math_problem,
),
400,
return render_template(
"register.html",
form=form,
require_invite_code=require_invite_code,
math_problem=math_problem,
)

if db.session.scalar(
db.exists(Username).where(Username._username == username).select()
):
flash("💔 Username already taken.", "error")
return (
render_template(
"register.html",
form=form,
require_invite_code=require_invite_code,
math_problem=math_problem,
),
409,
return render_template(
"register.html",
form=form,
require_invite_code=require_invite_code,
math_problem=math_problem,
)

user = User(password=password)
Expand Down

0 comments on commit 12fe30c

Please sign in to comment.