2017-03-13 09:36:21 -04:00
|
|
|
|
from iso3166 import countries
|
|
|
|
|
import string
|
|
|
|
|
import random
|
|
|
|
|
from ..models import User, Role
|
|
|
|
|
|
|
|
|
|
from flask_wtf import FlaskForm, RecaptchaField
|
|
|
|
|
from wtforms import StringField, PasswordField, BooleanField, SubmitField, SelectField, DecimalField
|
|
|
|
|
from wtforms import validators, ValidationError
|
|
|
|
|
from wtforms.fields.html5 import EmailField
|
|
|
|
|
|
|
|
|
|
class EditProfileForm(FlaskForm):
|
2017-06-25 10:11:52 -04:00
|
|
|
|
name = StringField('Name:', [validators.DataRequired(), validators.Length(3, 60)])
|
|
|
|
|
address = StringField('Address:', [validators.DataRequired(), validators.Length(2, 50)])
|
|
|
|
|
city = StringField('City:', [validators.DataRequired(), validators.Length(2,40)])
|
2017-03-13 09:36:21 -04:00
|
|
|
|
|
2017-06-25 10:11:52 -04:00
|
|
|
|
postcode = StringField('Postcode:')
|
2017-03-13 09:36:21 -04:00
|
|
|
|
|
|
|
|
|
clist = []
|
|
|
|
|
for c in countries:
|
|
|
|
|
clist.append((c.alpha2, c.name))
|
2017-06-25 10:11:52 -04:00
|
|
|
|
country = SelectField('Country:', choices=clist, default='BG')
|
2017-03-13 09:36:21 -04:00
|
|
|
|
|
2017-06-25 10:11:52 -04:00
|
|
|
|
phone = StringField('Phone:')
|
|
|
|
|
org_account = BooleanField('This is a business account.')
|
|
|
|
|
org_companyname = StringField('Company Name:')
|
|
|
|
|
org_regaddress = StringField('Company Address:')
|
|
|
|
|
org_responsible = StringField('Accountable Person (optional):')
|
|
|
|
|
org_vatnum = StringField('VAT Number:')
|
2018-02-07 11:19:55 -05:00
|
|
|
|
twofactor = BooleanField('Enable 2-factor authentication')
|
|
|
|
|
submit = SubmitField('Update')
|
2017-03-13 09:36:21 -04:00
|
|
|
|
|
|
|
|
|
class EditProfileAdminForm(FlaskForm):
|
|
|
|
|
email = StringField('Електроннa поща (логин):', [validators.DataRequired(), validators.Length(1, 64), validators.Email()])
|
2018-02-07 11:19:55 -05:00
|
|
|
|
confirmed = BooleanField('Activated')
|
|
|
|
|
role = SelectField('Role', coerce=int)
|
2017-03-13 09:36:21 -04:00
|
|
|
|
|
|
|
|
|
name = StringField('Лице за контакт:', [validators.DataRequired(), validators.Length(3, 60)])
|
|
|
|
|
address = StringField('Адрес:', [validators.DataRequired(), validators.Length(2, 50)])
|
|
|
|
|
city = StringField('Град:', [validators.DataRequired(), validators.Length(2,40)])
|
|
|
|
|
postcode = DecimalField('Пощенски Код:')
|
|
|
|
|
|
|
|
|
|
clist = []
|
|
|
|
|
for c in countries:
|
|
|
|
|
clist.append((c.alpha2, c.name))
|
|
|
|
|
country = SelectField('Държава:', choices=clist)
|
|
|
|
|
|
|
|
|
|
phone = DecimalField('Телефон:', [validators.DataRequired()])
|
2017-06-25 10:11:52 -04:00
|
|
|
|
org_account = BooleanField('This is a business account')
|
|
|
|
|
org_companyname = StringField('Company Name:')
|
|
|
|
|
org_regaddress = StringField('Company Address:')
|
|
|
|
|
org_responsible = StringField('Primary Contact:')
|
2017-05-13 05:46:43 -04:00
|
|
|
|
org_vatnum = StringField('ДДС Номер:')
|
2017-05-24 10:37:52 -04:00
|
|
|
|
twofactor = BooleanField('2-factor authentication')
|
2017-03-13 09:36:21 -04:00
|
|
|
|
submit = SubmitField('Обнови')
|
|
|
|
|
|
|
|
|
|
def __init__(self, user, *args, **kwargs):
|
|
|
|
|
super(EditProfileAdminForm, self).__init__(*args, **kwargs)
|
|
|
|
|
self.role.choices = [(role.pid, role.name)
|
|
|
|
|
for role in Role.query.order_by(Role.name).all()]
|
|
|
|
|
self.user = user
|
|
|
|
|
|
|
|
|
|
def validate_email(self, field):
|
|
|
|
|
if field.data != self.user.email and User.query.filter_by(email=field.data).first():
|
|
|
|
|
raise ValidationError('Email-а е вече регистриран.')
|
|
|
|
|
|
|
|
|
|
|