Advertisement
Guest User

Untitled

a guest
Aug 5th, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.47 KB | None | 0 0
  1. from flask_wtf import FlaskForm
  2. from wtforms import PasswordField, StringField, SubmitField
  3. from wtforms.validators import DataRequired, EqualTo, Length
  4.  
  5. from app.auth.functions import (check_if_email_not_in_db,
  6.                                 check_if_username_not_in_db,
  7.                                 make_password_contain_capital,
  8.                                 make_password_contain_number,
  9.                                 make_password_contain_special_characters
  10.                                 )
  11.  
  12.  
  13. class RegistrationForm(FlaskForm):
  14.     '''
  15.    This is in /register route.
  16.    The forms are username, email, password and confirm_password
  17.    '''
  18.     username = StringField('username',validators=
  19.     [
  20.     DataRequired(message='Username is required'),
  21.     Length(min=2, max=25 , message='Must be between 2 and 25 characters'),
  22.     check_if_username_not_in_db
  23.     ])  
  24.     email = StringField('email', validators=
  25.     [
  26.     DataRequired('Email is required'),
  27.     Length(min=4, max=35, message='Must be between 4 and 25 characters'),
  28.     check_if_email_not_in_db
  29.     ])
  30.     password = PasswordField('password',
  31.     validators=
  32.     [
  33.     DataRequired('Password is required'),
  34.     Length(min=8, max=25, message='Must be between 8 and 25 characters'),
  35.     EqualTo('confirm_password', message='The password field is not equal to the confirm password field'),
  36.     make_password_contain_capital,
  37.     make_password_contain_number,
  38.     make_password_contain_special_characters
  39.     ])
  40.  
  41.     confirm_password = PasswordField('confirm_password',
  42.     validators=
  43.     [
  44.     DataRequired('Does not match password'),
  45.     make_password_contain_capital,
  46.     make_password_contain_number,
  47.     make_password_contain_special_characters
  48.     ])
  49.     submit = SubmitField('Submit')
  50.  
  51.  
  52. from app.auth.functions import check_if_username_or_email_is_in_db
  53.  
  54.  
  55. class LoginForm(FlaskForm):
  56.     '''
  57.    This is in /Login route.
  58.    The forms are username, email, password and confirm_password
  59.    '''
  60.     username_or_email = StringField('username or email', validators=
  61.     [
  62.     DataRequired(message='Please use Username or Email'),
  63.     Length(min=4, max=35 ,message='Must be between 4 and 25 characters'),
  64.     check_if_username_or_email_is_in_db
  65.     ])
  66.     password = PasswordField('password', validators=
  67.     [
  68.     Length(min=8, max=25, message='Must be between 8 and 25 characters'),
  69.     ])
  70.     submit = SubmitField('Submit')
  71.  
  72.  
  73.  
  74.  
  75. class EmptyForm(FlaskForm):
  76.     pass
  77.  
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement