Skip to content

Commit

Permalink
Use StringField instead of TextField. Fixes pallets-eco#312
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Wright committed May 2, 2015
1 parent bc1f5dd commit 916f5ee
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions docs/customizing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ register form or override validators::
from flask_security.forms import RegisterForm

class ExtendedRegisterForm(RegisterForm):
first_name = TextField('First Name', [Required()])
last_name = TextField('Last Name', [Required()])
first_name = StringField('First Name', [Required()])
last_name = StringField('Last Name', [Required()])

security = Security(app, user_datastore,
register_form=ExtendedRegisterForm)
Expand Down
10 changes: 5 additions & 5 deletions flask_security/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from flask import request, current_app, flash
from flask_wtf import Form as BaseForm
from wtforms import TextField, PasswordField, validators, \
from wtforms import StringField, PasswordField, validators, \
SubmitField, HiddenField, BooleanField, ValidationError, Field
from flask_login import current_user
from werkzeug.local import LocalProxy
Expand Down Expand Up @@ -94,20 +94,20 @@ def __init__(self, *args, **kwargs):


class EmailFormMixin():
email = TextField(
email = StringField(
get_form_field_label('email'),
validators=[email_required, email_validator])


class UserEmailFormMixin():
user = None
email = TextField(
email = StringField(
get_form_field_label('email'),
validators=[email_required, email_validator, valid_user_email])


class UniqueEmailFormMixin():
email = TextField(
email = StringField(
get_form_field_label('email'),
validators=[email_required, email_validator, unique_user_email])

Expand Down Expand Up @@ -204,7 +204,7 @@ def validate(self):
class LoginForm(Form, NextFormMixin):
"""The default login form"""

email = TextField(get_form_field_label('email'))
email = StringField(get_form_field_label('email'))
password = PasswordField(get_form_field_label('password'))
remember = BooleanField(get_form_field_label('remember_me'))
submit = SubmitField(get_form_field_label('login'))
Expand Down
19 changes: 10 additions & 9 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from flask_security import Security
from flask_security.forms import LoginForm, RegisterForm, ConfirmRegisterForm, \
SendConfirmationForm, PasswordlessLoginForm, ForgotPasswordForm, ResetPasswordForm, \
ChangePasswordForm, TextField, PasswordField, email_required, email_validator, valid_user_email
ChangePasswordForm, StringField, PasswordField, email_required, email_validator, \
valid_user_email
from flask_security.utils import capture_reset_password_requests, md5, string_types

from utils import authenticate, init_app_with_options, populate_data
Expand Down Expand Up @@ -41,17 +42,17 @@ def test_register_blueprint_flag(app, sqlalchemy_datastore):
@pytest.mark.changeable()
def test_basic_custom_forms(app, sqlalchemy_datastore):
class MyLoginForm(LoginForm):
email = TextField('My Login Email Address Field')
email = StringField('My Login Email Address Field')

class MyRegisterForm(RegisterForm):
email = TextField('My Register Email Address Field')
email = StringField('My Register Email Address Field')

class MyForgotPasswordForm(ForgotPasswordForm):
email = TextField('My Forgot Email Address Field',
validators=[email_required, email_validator, valid_user_email])
email = StringField('My Forgot Email Address Field',
validators=[email_required, email_validator, valid_user_email])

class MyResetPasswordForm(ResetPasswordForm):
password = TextField('My Reset Password Field')
password = StringField('My Reset Password Field')

class MyChangePasswordForm(ChangePasswordForm):
password = PasswordField('My Change Password Field')
Expand Down Expand Up @@ -96,10 +97,10 @@ def test_confirmable_custom_form(app, sqlalchemy_datastore):
app.config['SECURITY_CONFIRMABLE'] = True

class MyRegisterForm(ConfirmRegisterForm):
email = TextField('My Register Email Address Field')
email = StringField('My Register Email Address Field')

class MySendConfirmationForm(SendConfirmationForm):
email = TextField('My Send Confirmation Email Address Field')
email = StringField('My Send Confirmation Email Address Field')

app.security = Security(app,
datastore=sqlalchemy_datastore,
Expand All @@ -119,7 +120,7 @@ def test_passwordless_custom_form(app, sqlalchemy_datastore):
app.config['SECURITY_PASSWORDLESS'] = True

class MyPasswordlessLoginForm(PasswordlessLoginForm):
email = TextField('My Passwordless Email Address Field')
email = StringField('My Passwordless Email Address Field')

app.security = Security(app,
datastore=sqlalchemy_datastore,
Expand Down

0 comments on commit 916f5ee

Please sign in to comment.