-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform.py
More file actions
146 lines (121 loc) · 4.75 KB
/
form.py
File metadata and controls
146 lines (121 loc) · 4.75 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
from flask_wtf import FlaskForm
from wtforms import (
StringField,
PasswordField,
SubmitField,
IntegerField,
BooleanField,
TelField,
TextAreaField,
# ValidationError
)
from flask_wtf.file import FileField, FileRequired, FileAllowed
from flask import flash
from wtforms.validators import (
DataRequired,
Length,
Email,
EqualTo,
NumberRange,
ValidationError,
Regexp,
)
class LoginForm(FlaskForm):
email = StringField("Email", validators=[DataRequired(), Email()])
password = PasswordField("Password", validators=[DataRequired()])
submit = SubmitField("Login")
class SendMoneyForm(FlaskForm):
amount = IntegerField("Amount", validators=[DataRequired(), NumberRange(min=100)])
add_beneficiary = BooleanField("Add as beneficiary")
transfer_pin = IntegerField(
"Enter 4 digits transfer pin", validators=[DataRequired()]
)
submit = SubmitField("Send")
class CreateTransferPin(FlaskForm):
transfer_pin = PasswordField(
"Create 4 digits transfer pin",
validators=[
DataRequired(),
Length(min=4, max=4, message="PIN must be exactly 4 digits"),
Regexp(r"^\d{4}$", message="PIN must contain only numbers"),
],
)
confirm_transfer_pin = PasswordField(
"Confirm 4 digits transfer pin",
validators=[
DataRequired(),
EqualTo("transfer_pin", message="PINs do not match"),
Length(min=4, max=4, message="PIN must be exactly 4 digits"),
],
)
secret_answer = StringField(
"Enter a secret answer (This answer cannot be changed)",
validators=[DataRequired(), Length(min=2, max=50)],
)
submit = SubmitField("Create")
class ChangeTransferPin(FlaskForm):
new_pin = IntegerField(
"Enter new 4 digits transfer pin",
validators=[DataRequired(), NumberRange(min=1000, max=9999)],
)
secret_answer = StringField(
"Enter your secret answer", validators=[DataRequired(), Length(min=2, max=50)]
)
submit = SubmitField("Change")
class RegistrationForm(FlaskForm):
first_name = StringField(
"First Name", validators=[DataRequired(), Length(min=2, max=30)]
)
last_name = StringField(
"Last Name", validators=[DataRequired(), Length(min=2, max=30)]
)
username = StringField(
"Username", validators=[DataRequired(), Length(min=2, max=25)]
)
email = StringField("Email", validators=[DataRequired(), Email()])
phone_number = TelField("Phone Number", validators=[DataRequired(), Length(max=11)])
invited_by = TelField("Invited by (optional)", validators=[Length(max=10)])
password = PasswordField("Password", validators=[DataRequired()])
confirm_password = PasswordField(
"Confirm Password", validators=[DataRequired(), EqualTo("password")]
)
submit = SubmitField("Sign Up")
class ContactForm(FlaskForm):
name = StringField("Name", validators=[DataRequired(), Length(min=2, max=20)])
email = StringField("Email", validators=[DataRequired(), Email()])
message = TextAreaField("Message", validators=[DataRequired(), Length(min=5)])
submit = SubmitField()
class ResetForm(FlaskForm):
email = StringField("Email", validators=[DataRequired(), Email()])
submit = SubmitField("Reset")
class ResetPasswordForm(FlaskForm):
password = PasswordField("Password", validators=[DataRequired()])
confirm_password = PasswordField(
"Confirm Password", validators=[DataRequired(), EqualTo("password")]
)
submit = SubmitField("Reset Password")
class PhotoForm(FlaskForm):
image = FileField(
validators=[FileRequired(), FileAllowed(["jpg", "jpeg", "png", "gif"])]
)
def validate_image(self, field):
if field.data:
if len(field.data.read()) > 1 * 1024 * 1024:
# flash("File size should be less than 1 MB.", category="danger")
raise ValidationError("File size should be less than 1 MB.")
class ConfirmAccount(FlaskForm):
account_number = TelField(
"Wallet Account Number", validators=[DataRequired(), Length(max=10)]
)
class CardForm(FlaskForm):
card_number = TelField("Card Number", validators=[DataRequired(), Length(max=16)])
card_name = StringField(
"Card Name", validators=[DataRequired(), Length(min=2, max=30)]
)
card_expiry = StringField("Card Expiry", validators=[DataRequired(), Length(max=5)])
card_cvv = TelField("Card CVV", validators=[DataRequired(), Length(max=3)])
card_pin = TelField("Card PIN", validators=[DataRequired(), Length(max=4)])
submit = SubmitField("Add Card")
class SaveMoneyForm(FlaskForm):
amount = IntegerField("Amount", validators=[DataRequired(), NumberRange(min=100)])
submit = SubmitField("Save")