Blame progit/login_forms.py

Pierre-Yves Chibon 33b534
# -*- coding: utf-8 -*-
Pierre-Yves Chibon 70d41a
Pierre-Yves Chibon 70d41a
"""
Pierre-Yves Chibon 70d41a
 (c) 2014 - Copyright Red Hat Inc
Pierre-Yves Chibon 70d41a
Pierre-Yves Chibon 70d41a
 Authors:
Pierre-Yves Chibon 70d41a
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon 70d41a
Pierre-Yves Chibon 70d41a
"""
Pierre-Yves Chibon 70d41a
Pierre-Yves Chibon 70d41a
Pierre-Yves Chibon 70d41a
# # pylint cannot import flask extension correctly
Pierre-Yves Chibon 70d41a
# pylint: disable=E0611,F0401
Pierre-Yves Chibon 70d41a
# # The forms here don't have specific methods, they just inherit them.
Pierre-Yves Chibon 70d41a
# pylint: disable=R0903
Pierre-Yves Chibon 70d41a
# # We apparently use old style super in our __init__
Pierre-Yves Chibon 70d41a
# pylint: disable=E1002
Pierre-Yves Chibon 70d41a
# # Couple of our forms do not even have __init__
Pierre-Yves Chibon 70d41a
# pylint: disable=W0232
Pierre-Yves Chibon 70d41a
Pierre-Yves Chibon 70d41a
Pierre-Yves Chibon 70d41a
from flask.ext import wtf
Pierre-Yves Chibon 70d41a
import wtforms
Pierre-Yves Chibon 70d41a
Pierre-Yves Chibon 4a9f35
from progit.forms import ConfirmationForm
Pierre-Yves Chibon 4a9f35
Pierre-Yves Chibon 70d41a
Pierre-Yves Chibon 70d41a
def same_password(form, field):
Pierre-Yves Chibon 70d41a
    ''' Check if the data in the field is the same as in the password field.
Pierre-Yves Chibon 70d41a
    '''
Pierre-Yves Chibon 70d41a
    if field.data != form.password.data:
Pierre-Yves Chibon 70d41a
        raise wtf.ValidationError('Both password fields should be equal')
Pierre-Yves Chibon 70d41a
Pierre-Yves Chibon 70d41a
Pierre-Yves Chibon 70d41a
class LostPasswordForm(wtf.Form):
Pierre-Yves Chibon 70d41a
    """ Form to ask for a password change. """
Pierre-Yves Chibon 70d41a
    username = wtforms.TextField(
Pierre-Yves Chibon 70d41a
        'username  *',
Pierre-Yves Chibon 70d41a
        [wtforms.validators.Required()]
Pierre-Yves Chibon 70d41a
    )
Pierre-Yves Chibon 70d41a
Pierre-Yves Chibon 70d41a
Pierre-Yves Chibon 70d41a
class ResetPasswordForm(wtf.Form):
Pierre-Yves Chibon 70d41a
    """ Form to reset one's password in the local database. """
Pierre-Yves Chibon 70d41a
    password = wtforms.PasswordField(
Pierre-Yves Chibon 70d41a
        'Password  *',
Pierre-Yves Chibon 70d41a
        [wtforms.validators.Required()]
Pierre-Yves Chibon 70d41a
    )
Pierre-Yves Chibon 70d41a
    confirm_password = wtforms.PasswordField(
Pierre-Yves Chibon 70d41a
        'Confirm password  *',
Pierre-Yves Chibon 70d41a
        [wtforms.validators.Required(), same_password]
Pierre-Yves Chibon 70d41a
    )
Pierre-Yves Chibon 70d41a
Pierre-Yves Chibon 70d41a
Pierre-Yves Chibon 70d41a
class LoginForm(wtf.Form):
Pierre-Yves Chibon 70d41a
    """ Form to login via the local database. """
Pierre-Yves Chibon 70d41a
    username = wtforms.TextField(
Pierre-Yves Chibon 70d41a
        'username  *',
Pierre-Yves Chibon 70d41a
        [wtforms.validators.Required()]
Pierre-Yves Chibon 70d41a
    )
Pierre-Yves Chibon 70d41a
    password = wtforms.PasswordField(
Pierre-Yves Chibon 70d41a
        'Password  *',
Pierre-Yves Chibon 70d41a
        [wtforms.validators.Required()]
Pierre-Yves Chibon 70d41a
    )
Pierre-Yves Chibon 70d41a
Pierre-Yves Chibon 70d41a
Pierre-Yves Chibon 70d41a
class NewUserForm(wtf.Form):
Pierre-Yves Chibon 70d41a
    """ Form to add a new user to the local database. """
Pierre-Yves Chibon 70d41a
    user = wtforms.TextField(
Pierre-Yves Chibon 70d41a
        'username  *',
Pierre-Yves Chibon 70d41a
        [wtforms.validators.Required()]
Pierre-Yves Chibon 70d41a
    )
Pierre-Yves Chibon 70d41a
    fullname = wtforms.TextField(
Pierre-Yves Chibon 70d41a
        'Full name',
Pierre-Yves Chibon 70d41a
        [wtforms.validators.Optional()]
Pierre-Yves Chibon 70d41a
    )
Pierre-Yves Chibon 70d41a
    email_address = wtforms.TextField(
Pierre-Yves Chibon 70d41a
        'Email address  *',
Pierre-Yves Chibon 70d41a
        [wtforms.validators.Required(), wtforms.validators.Email()]
Pierre-Yves Chibon 70d41a
    )
Pierre-Yves Chibon 70d41a
    password = wtforms.PasswordField(
Pierre-Yves Chibon 70d41a
        'Password  *',
Pierre-Yves Chibon 70d41a
        [wtforms.validators.Required()]
Pierre-Yves Chibon 70d41a
    )
Pierre-Yves Chibon 70d41a
    confirm_password = wtforms.PasswordField(
Pierre-Yves Chibon 70d41a
        'Confirm password  *',
Pierre-Yves Chibon 70d41a
        [wtforms.validators.Required(), same_password]
Pierre-Yves Chibon 70d41a
    )
Pierre-Yves Chibon 02df15
Pierre-Yves Chibon 02df15
Pierre-Yves Chibon 02df15
class NewGroupForm(wtf.Form):
Pierre-Yves Chibon 02df15
    """ Form to ask for a password change. """
Pierre-Yves Chibon 02df15
    group_name = wtforms.TextField(
Pierre-Yves Chibon 02df15
        'Group name  *',
Pierre-Yves Chibon 02df15
        [wtforms.validators.Required(), wtforms.validators.Length(max=16)]
Pierre-Yves Chibon 02df15
    )