Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jdabtieu committed Dec 7, 2023
1 parent b61e917 commit 3c28678
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
25 changes: 4 additions & 21 deletions src/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def login():
rows = db.execute("SELECT * FROM users WHERE username=:username",
username=request.form.get("username"))
code = login_chk(rows)
if code != 0:
if code:
return render_template("auth/login.html",
site_key=app.config['HCAPTCHA_SITE']), code

Expand Down Expand Up @@ -282,27 +282,10 @@ def register():
confirmation = request.form.get("confirmation")
email = request.form.get("email")

# Ensure username is valid
if not username or not verify_text(username):
flash('Invalid username', 'danger')
code = register_chk(username, password, confirmation, email)
if code:
return render_template("auth/register.html",
site_key=app.config['HCAPTCHA_SITE']), 400

# Ensure password is not blank
if not password or len(password) < 8:
flash('Password must be at least 8 characters', 'danger')
return render_template("auth/register.html",
site_key=app.config['HCAPTCHA_SITE']), 400
if not confirmation or password != confirmation:
flash('Passwords do not match', 'danger')
return render_template("auth/register.html",
site_key=app.config['HCAPTCHA_SITE']), 400

# Ensure email is valid
if "+" in email:
flash('Plus character not allowed in email', 'danger')
return render_template("auth/register.html",
site_key=app.config['HCAPTCHA_SITE']), 400
site_key=app.config['HCAPTCHA_SITE']), code
email = email.lower()

# Ensure captcha is valid
Expand Down
24 changes: 24 additions & 0 deletions src/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,30 @@ def login_chk(rows):
return 0


def register_chk(username, password, confirmation, email):
"""
Determines if the user is allowed to register
Used by register() in application.py
"""
if not username or not verify_text(username):
flash('Invalid username', 'danger')
return 400

if not password or len(password) < 8:
flash('Password must be at least 8 characters', 'danger')
return 400

if not confirmation or password != confirmation:
flash('Passwords do not match', 'danger')
return 400

if "+" in email:
flash('Plus character not allowed in email', 'danger')
return 400

return 0


def contest_ended(info):
"""
Determine if the contest from db query info has ended
Expand Down

0 comments on commit 3c28678

Please sign in to comment.