Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def check_if_username_or_email_is_in_db(form, field):
- '''
- if the username and email is in the db the code works,
- if not it raises an ValidationError.
- The if statement checks if the query is empty/has no values in db.
- This runs in the LoginForm in auth/forms.py
- '''
- username_or_email_form = field.data
- flash(f'username_or_email_form={username_or_email_form}')
- username_db = db.session.execute(db.select(User).filter_by(username=username_or_email_form)).scalar_one_or_none()
- email_db = db.session.execute(db.select(User).filter_by(email=username_or_email_form)).scalar_one_or_none()
- flash(f'username_db={username_db}')
- flash(f'email_db={email_db}')
- # if empty list [] return True
- # I want the username and email to to both be negative because I am using an username or an email to login
- if not db.session.execute(db.select(User).filter_by(username=username_or_email_form)).scalar_one_or_none() and \
- not db.session.execute(db.select(User).filter_by(email=username_or_email_form)).scalar_one_or_none():
- raise ValidationError('The username or email or password do not exist. Please retype your username or email or password.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement