1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
cyberplanificateur/app/forms.py

49 lines
2.1 KiB
Python
Raw Permalink Normal View History

from flask_wtf import FlaskForm
2019-04-29 15:53:18 +02:00
from wtforms import StringField, PasswordField, BooleanField, SubmitField, RadioField, IntegerField
from wtforms.validators import ValidationError, DataRequired, Email, EqualTo
from app.models import User
2019-04-29 15:53:18 +02:00
import trello, trello_credentials
class LoginForm(FlaskForm):
2019-04-29 15:53:18 +02:00
username = StringField("Username", validators = [DataRequired()])
password = PasswordField("Password", validators = [DataRequired()])
remember_me = BooleanField("Remember Me")
submit = SubmitField("Sign In")
2019-04-29 15:53:18 +02:00
def validate_username(self, username):
if not User.query.filter_by(username = username.data).first():
raise ValidationError("Invalid username.")
def validate_password(self, password):
user = User.query.filter_by(username = self.username.data).first()
if user and not user.check_password(password.data):
raise ValidationError("Invalid password.")
class RegistrationForm(FlaskForm):
2019-04-29 15:53:18 +02:00
username = StringField("Username", validators = [DataRequired()])
email = StringField("Email", validators = [DataRequired(), Email()])
password = PasswordField("Password", validators = [DataRequired()])
password2 = PasswordField(
2019-04-29 15:53:18 +02:00
"Repeat Password", validators = [DataRequired(), EqualTo("password")])
submit = SubmitField("Register")
def validate_username(self, username):
2019-04-29 15:53:18 +02:00
user = User.query.filter_by(username = username.data).first()
if user is not None:
raise ValidationError("Please use a different username.")
def validate_email(self, email):
2019-04-29 15:53:18 +02:00
user = User.query.filter_by(email = email.data).first()
if user is not None:
raise ValidationError("Please use a different email address.")
2019-04-29 15:53:18 +02:00
class TrelloAPIForm(FlaskForm):
token = StringField("Token", validators = [DataRequired()])
submit = SubmitField("Connect")
def validate_token(self, token):
try:
trello.TrelloClient(api_key = trello_credentials.api_key, token = token.data).list_boards()
except:
raise ValidationError("Invalid Trello Token")