From d8375ead15b8432eadd20aa72db116a40122a0cb Mon Sep 17 00:00:00 2001 From: "[esekyi]" <[sskert10@gmail.com]> Date: Tue, 10 Sep 2024 06:05:18 +0000 Subject: [PATCH] =?UTF-8?q?[Fixes=F0=9F=9B=A0=EF=B8=8F]=20Normalized=20db?= =?UTF-8?q?=20to=20ignore=20case-sensitivity=20-=20email?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/routes/auth_routes.py | 9 +++++++-- app/routes/user_routes.py | 15 ++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/routes/auth_routes.py b/app/routes/auth_routes.py index 4e5a67b..05c1f5b 100644 --- a/app/routes/auth_routes.py +++ b/app/routes/auth_routes.py @@ -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) diff --git a/app/routes/user_routes.py b/app/routes/user_routes.py index bb7e16f..2179d0d 100644 --- a/app/routes/user_routes.py +++ b/app/routes/user_routes.py @@ -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')) @@ -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')