Allow Emails to be 254 characters long.

This commit is contained in:
Patrick Jentsch 2019-09-12 14:24:43 +02:00
parent c6597d4e37
commit f0197b5af6
3 changed files with 21 additions and 13 deletions

View File

@ -1,5 +1,6 @@
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField, ValidationError, TextAreaField
from wtforms import (StringField, PasswordField, BooleanField, SubmitField,
ValidationError)
from wtforms.validators import DataRequired, Length, Email, Regexp, EqualTo
from ..models import User
@ -13,13 +14,20 @@ class LoginForm(FlaskForm):
class RegistrationForm(FlaskForm):
email = StringField('Email', validators=[DataRequired(), Email()])
username = StringField('Username', validators=[
DataRequired(), Length(1, 64),
Regexp('^[A-Za-z][A-Za-z0-9_.]*$', 0,
'Usernames must have only letters, numbers, dots or '
'underscores')])
password = PasswordField('Password', validators=[
DataRequired(), EqualTo('password2', message='Passwords must match.')])
username = StringField(
'Username',
validators=[DataRequired(),
Length(1, 64),
Regexp('^[A-Za-z][A-Za-z0-9_.]*$',
0,
'Usernames must have only letters, numbers, dots '
'or underscores')]
)
password = PasswordField(
'Password',
validators=[DataRequired(),
EqualTo('password2', message='Passwords must match.')]
)
password2 = PasswordField('Confirm password', validators=[DataRequired()])
submit = SubmitField('Register')
@ -79,8 +87,8 @@ class ChangePasswordForm(FlaskForm):
class EditProfileForm(FlaskForm):
email = StringField('Change Email', validators=[Length(0, 64),
DataRequired()])
email = StringField('Change Email',
validators=[Length(0, 254), DataRequired()])
submit = SubmitField('Change Email')
def __init__(self, user, *args, **kwargs):

View File

@ -107,7 +107,7 @@ class User(UserMixin, db.Model):
# Primary key
id = db.Column(db.Integer, primary_key=True)
confirmed = db.Column(db.Boolean, default=False)
email = db.Column(db.String(64), unique=True, index=True)
email = db.Column(db.String(254), unique=True, index=True)
password_hash = db.Column(db.String(128))
registration_date = db.Column(db.DateTime(), default=datetime.utcnow)
role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))

View File

@ -30,7 +30,7 @@ def upgrade():
op.create_table('users',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('confirmed', sa.Boolean(), nullable=True),
sa.Column('email', sa.String(length=64), nullable=True),
sa.Column('email', sa.String(length=254), nullable=True),
sa.Column('password_hash', sa.String(length=128), nullable=True),
sa.Column('registration_date', sa.DateTime(), nullable=True),
sa.Column('role_id', sa.Integer(), nullable=True),