| Total Complexity | 4 |
| Total Lines | 23 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | from flask_wtf import Form |
||
| 8 | class LoginForm(Form): |
||
| 9 | username = StringField(u'Username', validators=[validators.required()]) |
||
| 10 | password = PasswordField(u'Password', validators=[validators.optional()]) |
||
| 11 | |||
| 12 | def validate(self): |
||
| 13 | check_validate = super(LoginForm, self).validate() |
||
| 14 | |||
| 15 | # if our validators do not pass |
||
| 16 | if not check_validate: |
||
| 17 | return False |
||
| 18 | |||
| 19 | # Does our the exist |
||
| 20 | user = User.query.filter_by(username=self.username.data).first() |
||
| 21 | if not user: |
||
| 22 | self.username.errors.append('Invalid username or password') |
||
| 23 | return False |
||
| 24 | |||
| 25 | # Do the passwords match |
||
| 26 | if not user.check_password(self.password.data): |
||
| 27 | self.username.errors.append('Invalid username or password') |
||
| 28 | return False |
||
| 29 | |||
| 30 | return True |
||
| 31 |