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

View File

@ -107,7 +107,7 @@ class User(UserMixin, db.Model):
# Primary key # Primary key
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
confirmed = db.Column(db.Boolean, default=False) 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)) password_hash = db.Column(db.String(128))
registration_date = db.Column(db.DateTime(), default=datetime.utcnow) registration_date = db.Column(db.DateTime(), default=datetime.utcnow)
role_id = db.Column(db.Integer, db.ForeignKey('roles.id')) role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))

View File

@ -30,7 +30,7 @@ def upgrade():
op.create_table('users', op.create_table('users',
sa.Column('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
sa.Column('confirmed', sa.Boolean(), nullable=True), 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('password_hash', sa.String(length=128), nullable=True),
sa.Column('registration_date', sa.DateTime(), nullable=True), sa.Column('registration_date', sa.DateTime(), nullable=True),
sa.Column('role_id', sa.Integer(), nullable=True), sa.Column('role_id', sa.Integer(), nullable=True),