"""Module that handles the authorization forms."""
from flask_wtf import FlaskForm
from wtforms import (
    SubmitField, StringField, PasswordField, BooleanField, ValidationError,
    RadioField, TextField, SelectMultipleField)
from wtforms.validators import (
    Required, Length, Email, EqualTo, DataRequired)
from wtforms import widgets
from ..database import User


class LoginForm(FlaskForm):
    """Login form."""

    email = StringField(
        'Email', validators=[DataRequired(), Length(1, 64), Email()])
    password = PasswordField(
        'Password', validators=[DataRequired(), Length(4, 64)])
    remember_me = BooleanField('Keep me logged in')
    submit = SubmitField('Log In')


class RegistrationForm(FlaskForm):
    """User registration form."""

    email_validators = [DataRequired(), Length(1, 64), Email()]
    email = StringField('Email', validators=email_validators)
    password_validators = [
        DataRequired(), EqualTo('password2', message='Passwords must match.'),
        Length(4, 64)]
    password = PasswordField('Password', validators=password_validators)
    password2 = PasswordField('Confirm password', validators=[Required()])
    submit = SubmitField('Register')

    def validate_email(self, field):
        """Validate email address."""
        if User.query.filter_by(email=field.data).first():
            raise ValidationError('Email already registered.')


class ChangePasswordForm(FlaskForm):
    """Change password form."""

    old_password = PasswordField('Old password', validators=[DataRequired()])
    password = PasswordField('New password', validators=[
        DataRequired(), EqualTo('password2', message='Passwords must match.'),
        Length(4, 64)])
    password2 = PasswordField('Confirm new password',
                              validators=[DataRequired()])
    submit = SubmitField('Update Password')


class PasswordResetRequestForm(FlaskForm):
    """Password reset request form."""

    email = StringField(
        'Email', validators=[DataRequired(), Length(1, 64), Email()])
    submit = SubmitField('Reset Password')


class PasswordResetForm(FlaskForm):
    """Password reset form."""

    password = PasswordField('New Password', validators=[
        DataRequired(), EqualTo('password2', message='Passwords must match'),
        Length(4, 64)])
    password2 = PasswordField('Confirm password', validators=[DataRequired()])
    submit = SubmitField('Reset Password')


class ChangeEmailForm(FlaskForm):
    """Change email form."""

    email = StringField(
        'New Email', validators=[DataRequired(), Length(1, 64), Email()])
    password = PasswordField(
        'Password', validators=[DataRequired(), Length(4, 64)])
    submit = SubmitField('Update Email Address')

    def validate_email(self, field):
        """Validate email address."""
        if User.query.filter_by(email=field.data).first():
            raise ValidationError('Email already registered.')


class DeleteUserForm(FlaskForm):
    """Delete user form."""

    yes = SubmitField('Yes')
    no = SubmitField('No')


class ChangeGroupForm(FlaskForm):
    """Change group form."""

    groups = RadioField('', validators=[DataRequired()])
    submit = SubmitField('Submit')
    cancel = SubmitField('Cancel')


class ModifyGroupNameForm(FlaskForm):
    """Modify group form."""

    group_name = TextField('Group Name:', validators=[DataRequired()])
    modify = SubmitField('Modify')
    cancel = SubmitField('Cancel')


class MultiCheckboxField(SelectMultipleField):
    """
    A multiple-select, except displays a list of checkboxes.

    Iterating the field will produce subfields, allowing custom rendering of
    the enclosed checkbox fields.
    """

    widget = widgets.ListWidget(prefix_label=False)
    option_widget = widgets.CheckboxInput()


class DeleteGroupMemberForm(FlaskForm):
    """Delete group member form."""

    del_email = MultiCheckboxField('')
    delete = SubmitField('Delete')
    cancel = SubmitField('Cancel')


class AddGroupMemberForm(FlaskForm):
    """Delete group member form."""

    email_validators = [DataRequired(), Length(0, 64), Email()]
    add_email = StringField('Email:', validators=email_validators)
    add = SubmitField('Add')
    cancel = SubmitField('Cancel')

@@ -203,29 +203,8 @@
 ield
-, SelectMultipleField
 )%0Afr
@@ -291,31 +291,34 @@
 d)%0Afrom 
-wtforms
+..database
  import 
 widgets%0A
@@ -313,23 +313,20 @@
 ort 
-widgets
+User
 %0Afrom ..
 data
@@ -321,36 +321,47 @@
 %0Afrom ..
-database import User
+forms import MultiCheckboxField
 %0A%0A%0Aclass
@@ -3472,343 +3472,8 @@
 )%0A%0A%0A
-class MultiCheckboxField(SelectMultipleField):%0A    %22%22%22%0A    A multiple-select, except displays a list of checkboxes.%0A%0A    Iterating the field will produce subfields, allowing custom rendering of%0A    the enclosed checkbox fields.%0A    %22%22%22%0A%0A    widget = widgets.ListWidget(prefix_label=False)%0A    option_widget = widgets.CheckboxInput()%0A%0A%0A
 clas

Remove redundant class