Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def validate(self, extra_validators=None):
- """
- Validates the form by calling `validate` on each field.
- :param extra_validators:
- If provided, is a dict mapping field names to a sequence of
- callables which will be passed as extra validators to the field's
- `validate` method.
- Returns `True` if no errors occur.
- """
- self._errors = None
- success = True
- for name, field in iteritems(self._fields):
- if extra_validators is not None and name in extra_validators:
- extra = extra_validators[name]
- else:
- extra = tuple()
- if not field.validate(self, extra):
- success = False
- return success
- from wtforms import StringField, BooleanField, PasswordField, validators, ValidationError, HiddenField
- from flask_wtf import Form
- class LoginForm(RedirectForm):
- email = StringField('Email', [
- validators.DataRequired(),
- validators.Email('Invalid Email Address')
- ])
- password = PasswordField('Password', [
- validators.DataRequired()
- ])
- def validate(self):
- if not Form.validate(self):
- return False
- user = User.query.filter_by(email=self.email.data.lower()).first()
- if user and user.check_password(self.password.data):
- self.user = user
- return True
- else:
- self.email.errors.append("Invalid e-mail or password")
- return False
- def get_user(self):
- return self.user
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement