Advertisement
Guest User

Untitled

a guest
Aug 13th, 2023
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. #functions for routes.py
  2.  
  3. from flask import flash, redirect, url_for
  4.  
  5.  
  6. # allow different imports so the code works during pytest + None pytest
  7.  
  8. # None pytest code
  9.  
  10. import os
  11. env = os.environ.get('TEST_ENV', 'default')
  12. if env == 'test':
  13.     from app.tests.models import UserTest as USer
  14.     print(User)
  15. # This will run when the env is not Pytestconfig
  16. else:
  17.     from app.models import User
  18.     print(User)
  19.  
  20.  
  21. def check_if_username_or_email_is_in_db(username_or_email_form):
  22.     '''
  23.    if the username or email is in the db the code works,
  24.    if not it redirects.
  25.  
  26.    This runs in the /login route.
  27.    The if statement checks if the query is empty/has no values in db.
  28.    '''
  29.     # makes it so db will run if empty list []
  30.  
  31.  
  32.     # Why do I need this and ca
  33.  
  34.     if not User.query.filter_by(username=username_or_email_form).first():
  35.         # The username does not exist or you mistyped the username.
  36.         # flash("Please fill out the correct username to Login.  
  37.        
  38.         print('unsuccesful redirects')  
  39.         return redirect(url_for('auth.login'))
  40.    
  41.     elif not User.query.filter_by(email=username_or_email_form).first():
  42.         # The email does not exist or you mistyped the email.
  43.         # Please fill out the correct email to Login.    
  44.         print('unsuccesful redirects')  
  45.         return redirect(url_for('auth.login'))  
  46.    
  47.     else:
  48.         print('successful = None')
  49.         return None # will this cause an error
  50.     # Success the username or email does exist and you can Login.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement