File: //home/arjun/projects/buyercall_forms/buyercall/buyercall/blueprints/user/forms.py
import logging
from flask_wtf import FlaskForm, RecaptchaField
from wtforms import HiddenField, StringField, PasswordField, SelectField, IntegerField, BooleanField, RadioField
from wtforms.validators import DataRequired, Length, Optional, Regexp, NumberRange
from wtforms_alchemy import Unique
from wtforms_components import EmailField, Email
from flask_babel import lazy_gettext as _
try:
from instance import settings
LANGUAGES = settings.LANGUAGES
except ImportError:
logging.error('Ensure __init__.py and settings.py both exist in instance/')
exit(1)
except AttributeError:
from config import settings
LANGUAGES = settings.LANGUAGES
from buyercall.lib.util_wtforms import ModelForm, choices_from_dict
from buyercall.blueprints.user.models import User, db
from buyercall.blueprints.user.validations import ensure_identity_exists, \
ensure_existing_password_matches
class LoginForm(FlaskForm):
next = HiddenField()
identity = StringField(_('Email address'),
[DataRequired(), Length(3, 254)])
password = PasswordField('Password', [DataRequired(), Length(8, 128)])
remember = BooleanField(_('Stay signed in'))
class BeginPasswordResetForm(FlaskForm):
identity = StringField(_('Email address'),
[DataRequired(),
Length(3, 254),
ensure_identity_exists]
)
class PasswordResetForm(FlaskForm):
reset_token = HiddenField()
password = PasswordField(_('New password'), [DataRequired(), Length(8, 128)])
class SignupForm(ModelForm):
firstname = StringField(_('First name'), [Optional(), Length(1, 128)])
lastname = StringField(_('Last name'), [Optional(), Length(1, 128)])
email = EmailField(validators=[
DataRequired(),
])
password = PasswordField(_('Password'), [DataRequired(), Length(8, 128)])
phonenumber = StringField(_('Phone number'), [DataRequired(), Length(8, 20)])
company = StringField(_('Company'), [DataRequired(), Length(2, 256)])
tos_agreement = BooleanField(_(''), [DataRequired()])
recaptcha = RecaptchaField()
class UpdateCredentials(ModelForm):
email = EmailField(validators=[
Email(),
Unique(
User.email,
get_session=lambda: db.session
)
])
current_password = PasswordField(_('Current Password'),
[DataRequired(),
Length(8, 128),
ensure_existing_password_matches]
)
password = PasswordField(_('New Password (optional)'), [Optional(), Length(8, 128)])
class UpdatePersonalDetails(ModelForm):
firstname = StringField(_('First name'), [Optional(), Length(1, 128)])
lastname = StringField(_('Last name'), [Optional(), Length(1, 128)])
company = StringField(_('Company'), [Optional(), Length(1, 128)])
class UpdateLocale(ModelForm):
locale = SelectField(_('Language'), [DataRequired()],
choices=choices_from_dict(LANGUAGES))
class UpdateSecurity(FlaskForm):
two_factor_auth = BooleanField('Enable two step verification')
auth_method = HiddenField()
choice = RadioField('Choose two step verification method', validators=[DataRequired()])
class UpdatePhoneNumber(ModelForm):
phonenumber = StringField(_('Mobile Phone Number'), [DataRequired(), Length(1, 20)])
class TwoFactorAuthForm(FlaskForm):
code = IntegerField('Enter Verification Code', [DataRequired()])