from flask_wtf import FlaskForm, RecaptchaField

from wtforms import StringField, PasswordField, BooleanField, SubmitField, SelectField, DecimalField
from wtforms import validators, ValidationError
from wtforms.fields import EmailField
from models import User

class LoginForm(FlaskForm):
    email = EmailField('', [validators.DataRequired(), validators.Length(1,64), validators.Email()], render_kw={"placeholder": "username"})
    password = PasswordField('', [validators.DataRequired(), validators.Length(1,128)], render_kw={"placeholder": "password"})
    remember_me = BooleanField('Remember?', render_kw={"placeholder": "remember"})
    #recaptcha = RecaptchaField()
    submit = SubmitField('Login', render_kw={"placeholder": "submit"})

class RegistrationForm(FlaskForm):
    email = StringField('E-Mail', [validators.DataRequired(), validators.Length(6,35), validators.Email()])
    def validate_email(self, field):
        if User.query.filter_by(email=field.data).first():
            raise ValidationError('Error. Please try again.')
    password = PasswordField('Password', [validators.DataRequired(), validators.EqualTo('confirm', message='Both passwords must be equal')])
    confirm = PasswordField('Your password again', [validators.DataRequired()])
    accept_tos = BooleanField('I accept the <a href="/terms">Terms of Service</a>', [validators.DataRequired()])
    recaptcha = RecaptchaField()
    submit = SubmitField('REGISTER')
    
