-
Notifications
You must be signed in to change notification settings - Fork 1
/
forms.py
63 lines (56 loc) · 1.82 KB
/
forms.py
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
from wtforms import Form
from wtforms import StringField, TextField, PasswordField,TextAreaField
from wtforms.fields.html5 import EmailField
from wtforms import validators
from wtforms import HiddenField
from models import User
def length_honeypot(form,field):
if len(field.data) > 0:
raise validators.ValidationError("El campo debe estar vacio")
class CommentForm(Form):
comment = TextField('Comentario',
[
validators.required(message="Requiere usuario"),
])
honeypot = HiddenField("",[length_honeypot])
class FormLogin(Form):
username = StringField('username',
[
validators.length(min=4,max=35,message="Ingrese usuario valido"),
validators.required(message="Requiere usuario")
])
password = PasswordField('password',
[
validators.length(min=4,max=35,message="Ingrese passwrod valido"),
validators.required(message="Requiere password")
])
honeypot = HiddenField("",[length_honeypot])
class FormCreate(Form):
username = StringField('username',
[
validators.length(min=4,max=35,message="Ingrese usuario valido"),
validators.required(message="Requiere usuario")
])
email = EmailField('Correro electronico',
[
validators.Email()
])
password = PasswordField('password',
[
validators.length(min=4,max=35,message="Ingrese passwrod valido"),
validators.required(message="Requiere password")
])
honeypot = HiddenField("",[length_honeypot])
def validate_username(form,field):
username =field.data
user = User.query.filter_by(username=username).first()
if user is not None:
raise validators.ValidationError("El usuario ya esta en uso")
class FormNewPost(Form):
title = StringField('Titulo',[
validators.required('Se requiere este campo')
])
content = TextAreaField('Content',[
validators.required('Se requiere este campo')
])
honeypot = HiddenField("",[length_honeypot])