<gh_stars>0
from flask_wtf import FlaskForm
from wtforms import HiddenField, PasswordField, StringField
from wtforms.fields.html5 import EmailField
from wtforms.validators import DataRequired, Length, Optional, Regexp, Email
from wtforms_alchemy import Unique

from utils.util_wtforms import ModelForm
from snakeeyes.blueprints.user.models import User
from snakeeyes.blueprints.user.validations import (
    ensure_existing_password_matches, ensure_identity_exists)


class LoginForm(FlaskForm):
    next = HiddenField()
    identity = StringField('Username or email',
                           [DataRequired(), Length(3, 254)])
    password = PasswordField('Password', [DataRequired(), Length(8, 128)])
    # remember = BooleanField('Stay signed in')


class BeginPasswordResetForm(FlaskForm):
    identity = StringField('Username or email',
                           [DataRequired(),
                            Length(3, 254),
                            ensure_identity_exists])


class PasswordResetForm(FlaskForm):
    reset_token = HiddenField()
    password = PasswordField('Password', [DataRequired(), Length(8, 128)])


class SignupForm(ModelForm):
    email = EmailField(validators=[
        DataRequired(),
        Email(),
        Unique(User.email)
    ])
    password = PasswordField('Password', [DataRequired(), Length(8, 128)])


class WelcomeForm(ModelForm):
    username_message = 'Letters, numbers and underscores only please.'

    username = StringField(validators=[
        Unique(User.username),
        DataRequired(),
        Length(1, 16),
        Regexp('^[A-Za-z][A-Za-z0-9_]*$', message=username_message)
    ])


class UpdateCredentials(ModelForm):
    current_password = PasswordField('<PASSWORD> password',
                                     [DataRequired(),
                                      Length(8, 128),
                                      ensure_existing_password_matches])

    email = EmailField(validators=[
        Email(), Unique(User.email)
    ])
    password = PasswordField('Password', [Optional(), Length(8, 128)])

from flask_wtf import FlaskForm
from wtforms import HiddenField, PasswordField, StringField
from wtforms.fields.html5 import EmailField
from wtforms.validators import DataRequired, Length, Optional, Regexp, Email
from wtforms_alchemy import Unique

from utils.util_wtforms import ModelForm
from snakeeyes.blueprints.user.models import User
from snakeeyes.blueprints.user.validations import (
    ensure_existing_password_matches, ensure_identity_exists)


class LoginForm(FlaskForm):
    next = HiddenField()
    identity = StringField('Username or email',
                           [DataRequired(), Length(3, 254)])
    password = PasswordField('Password', [DataRequired(), Length(8, 128)])
    # remember = BooleanField('Stay signed in')


class BeginPasswordResetForm(FlaskForm):
    identity = StringField('Username or email',
                           [DataRequired(),
                            Length(3, 254),
                            ensure_identity_exists])


class PasswordResetForm(FlaskForm):
    reset_token = HiddenField()
    password = PasswordField('Password', [DataRequired(), Length(8, 128)])


class SignupForm(ModelForm):
    email = EmailField(validators=[
        DataRequired(),
        Email(),
        Unique(User.email)
    ])
    password = PasswordField('Password', [DataRequired(), Length(8, 128)])


class WelcomeForm(ModelForm):
    username_message = 'Letters, numbers and underscores only please.'

    username = StringField(validators=[
        Unique(User.username),
        DataRequired(),
        Length(1, 16),
        Regexp('^[A-Za-z][A-Za-z0-9_]*$', message=username_message)
    ])


class UpdateCredentials(ModelForm):
    current_password = PasswordField('<PASSWORD> password',
                                     [DataRequired(),
                                      Length(8, 128),
                                      ensure_existing_password_matches])

    email = EmailField(validators=[
        Email(), Unique(User.email)
    ])
    password = PasswordField('Password', [Optional(), Length(8, 128)])
# remember = BooleanField('Stay signed in')