diff options
Diffstat (limited to 'pyaggr3g470r/forms.py')
-rw-r--r-- | pyaggr3g470r/forms.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/pyaggr3g470r/forms.py b/pyaggr3g470r/forms.py index 72bb3909..c7054b85 100644 --- a/pyaggr3g470r/forms.py +++ b/pyaggr3g470r/forms.py @@ -6,3 +6,21 @@ from wtforms import TextField, TextAreaField, PasswordField, SubmitField, valida import models +class SigninForm(Form): + email = TextField("Email", [validators.Required("Please enter your email address."), validators.Email("Please enter your email address.")]) + password = PasswordField('Password', [validators.Required("Please enter a password.")]) + submit = SubmitField("Sign In") + + def __init__(self, *args, **kwargs): + Form.__init__(self, *args, **kwargs) + + def validate(self): + if not Form.validate(self): + return False + + user = models.User.objects(email = self.email.data).first() + if user and user.check_password(self.password.data): + return True + else: + self.email.errors.append("Invalid e-mail or password") + return False
\ No newline at end of file |