-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathforms.py
More file actions
33 lines (28 loc) · 1.57 KB
/
forms.py
File metadata and controls
33 lines (28 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField, BooleanField, FileField
from wtforms.validators import DataRequired, Length, Email, EqualTo, ValidationError
from models import User
from flask_wtf.file import FileAllowed
class RegistrationForm(FlaskForm):
username = StringField('Username', validators=[DataRequired(), Length(2, 20)])
email = StringField('Email', validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired()])
confirm_password = PasswordField('Confirm Password', validators=[DataRequired(), EqualTo('password')])
submit = SubmitField('Sign Up')
# Additional validation to check if username or email already exists
def validate_username(self, username):
user = User.query.filter_by(username=username.data).first()
if user:
raise ValidationError('Username already taken. Please choose another.')
def validate_email(self, email):
user = User.query.filter_by(email=email.data).first()
if user:
raise ValidationError('Email already registered. Please choose another.')
class LoginForm(FlaskForm):
email = StringField('Email', validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired()])
remember = BooleanField('Remember Me')
submit = SubmitField('Login')
class SubmissionForm(FlaskForm):
data_file = FileField('Upload Prediction', validators=[DataRequired(), FileAllowed(['txt', 'csv', 'tsv', 'gz'], 'Text files only!')])
submit = SubmitField('Submit')