Skip to content

Commit

Permalink
[Fixes🛠️] Normalized db to ignore case-sensitivity - email
Browse files Browse the repository at this point in the history
  • Loading branch information
[esekyi] committed Sep 10, 2024
1 parent 5db6b0e commit d8375ea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
9 changes: 7 additions & 2 deletions app/routes/auth_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ def login():
return redirect(url_for('user_routes.user_profile', user_id=current_user.id))

if request.method == 'POST':
email = request.form["email"]
email = request.form.get("email").strip().lower()
password = request.form["password"]
next_page = request.form.get("next")
remember_me = request.form.get('remember_me')

# Convert checkbox to boolean
remember = True if remember_me == "on" else False

user = User.query.filter_by(email=email).first()

if user and check_password_hash(user.password_hash, password):
login_user(user)
login_user(user, remember=remember)

if next_page and is_safe_url(next_page):
return redirect(next_page)
Expand Down
15 changes: 10 additions & 5 deletions app/routes/user_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ def register():
first_name = data.get('first_name')
last_name = data.get('last_name')
username = data.get('username')
email = data.get('email')
email = data.get('email').strip().lower()
password = data.get('password')
confirm_password = request.form.get('confirm_password')

if not first_name or not last_name or not username or not email or not password:
if not first_name or not last_name or not username or not email or not password or not confirm_password:
flash('All fields are required', 'error')
return redirect(url_for('user_routes.register'))

Expand All @@ -56,9 +57,13 @@ def register():
return redirect(url_for('user_routes.register'))

try:
create_user(first_name, last_name, username, email, password)
flash('Registration successful, proceed to login!', 'info')
return redirect(url_for('auth.login'))
if password == confirm_password:
create_user(first_name, last_name, username, email, password)
flash('Registration successful, proceed to login!', 'info')
return redirect(url_for('auth.login'))
else:
flash('Password and confirm password do not match', 'error')

except Exception as e:
db.session.rollback()
flash('An error occured during registeration. Please try again', 'error')
Expand Down

0 comments on commit d8375ea

Please sign in to comment.