2019-04-29 01:49:40 +02:00
|
|
|
from flask_wtf import FlaskForm
|
2019-04-29 15:53:18 +02:00
|
|
|
from wtforms import StringField, PasswordField, BooleanField, SubmitField, RadioField, IntegerField
|
2019-04-29 01:49:40 +02:00
|
|
|
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
|
2019-04-29 01:49:40 +02:00
|
|
|
|
|
|
|
class LoginForm(FlaskForm):
|
2019-04-29 15:53:18 +02:00
|
|
|
username = StringField("Username", validators = [DataRequired()])
|
|
|
|
password = PasswordField("Password", validators = [DataRequired()])
|
2019-04-29 01:49:40 +02:00
|
|
|
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.")
|
|
|
|
|
2019-04-29 01:49:40 +02:00
|
|
|
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()])
|
2019-04-29 01:49:40 +02:00
|
|
|
password2 = PasswordField(
|
2019-04-29 15:53:18 +02:00
|
|
|
"Repeat Password", validators = [DataRequired(), EqualTo("password")])
|
2019-04-29 01:49:40 +02:00
|
|
|
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()
|
2019-04-29 01:49:40 +02:00
|
|
|
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()
|
2019-04-29 01:49:40 +02:00
|
|
|
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")
|