Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #functions for routes.py
- from flask import flash, redirect, url_for
- # allow different imports so the code works during pytest + None pytest
- # None pytest code
- import os
- env = os.environ.get('TEST_ENV', 'default')
- if env == 'test':
- from app.tests.models import UserTest as USer
- print(User)
- # This will run when the env is not Pytestconfig
- else:
- from app.models import User
- print(User)
- def check_if_username_or_email_is_in_db(username_or_email_form):
- '''
- if the username or email is in the db the code works,
- if not it redirects.
- This runs in the /login route.
- The if statement checks if the query is empty/has no values in db.
- '''
- # makes it so db will run if empty list []
- # Why do I need this and ca
- if not User.query.filter_by(username=username_or_email_form).first():
- # The username does not exist or you mistyped the username.
- # flash("Please fill out the correct username to Login.
- print('unsuccesful redirects')
- return redirect(url_for('auth.login'))
- elif not User.query.filter_by(email=username_or_email_form).first():
- # The email does not exist or you mistyped the email.
- # Please fill out the correct email to Login.
- print('unsuccesful redirects')
- return redirect(url_for('auth.login'))
- else:
- print('successful = None')
- return None # will this cause an error
- # Success the username or email does exist and you can Login.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement