| from flask_wtf import FlaskForm |
| from wtforms import StringField, PasswordField, BooleanField, SubmitField, TextAreaField, SelectField |
| from wtforms.validators import ValidationError, DataRequired, Email, EqualTo, Length |
| |
| from app.models import User |
| |
| class LoginForm(FlaskForm): |
| email = StringField('Email', validators=[DataRequired()]) |
| password = PasswordField('Password', validators=[DataRequired()]) |
| remember_me = BooleanField('Remember Me') |
| submit = SubmitField('Sign In') |
| |
| class RequestPasswordResetForm(FlaskForm): |
| email = StringField('Email', validators=[DataRequired()]) |
| submit = SubmitField('Reset Password') |
| |
| class PasswordResetForm(FlaskForm): |
| email = StringField('Email', validators=[DataRequired()]) |
| password = PasswordField('New Password (minimum 8 characters)', validators=[DataRequired()]) |
| password2 = PasswordField( |
| 'Repeat New Password', validators=[DataRequired(), EqualTo('password')]) |
| submit = SubmitField('Reset Password') |
| |
| def validate_password(self, password): |
| if len(password.data) < 8 or len(password.data) > 24: |
| raise ValidationError('Password must be between 8 and 24 characters!') |
| |
| class RegistrationForm(FlaskForm): |
| #username = StringField('Username', validators=[DataRequired()]) |
| email = StringField('Email', validators=[DataRequired(), Email()]) |
| password = PasswordField('Password (minimum 8 characters)', validators=[DataRequired()]) |
| password2 = PasswordField( |
| 'Repeat Password', validators=[DataRequired(), EqualTo('password')]) |
| #accept_tos = BooleanField('By checking this box, I accept <a href='http://www.google.com'>Terms & Conditions</a>', validators=[DataRequired()]) |
| submit = SubmitField('Register') |
| |
| def validate_email(self, email): |
| user = User.query.filter_by(email=email.data).first() |
| if user is not None: |
| raise ValidationError('Please use a different email address!') |
| |
| def validate_password(self, password): |
| if len(password.data) < 8 or len(password.data) > 24: |
| raise ValidationError('Password must be between 8 and 24 characters!') |
| |
| class ProfileForm(FlaskForm): |
| email = StringField('Email', validators=[Length(min=0, max=140)], render_kw={'readonly': True}) |
| organization = StringField('Organization', validators=[Length(min=0, max=140)], render_kw={'readonly': True}) |
| role = StringField('Role', validators=[Length(min=0, max=140)], render_kw={'readonly': True}) |
| fullname = StringField('Fullname', validators=[Length(min=0, max=140)]) |
| ssh_public_key = TextAreaField('SSH Public Key') |
| registered_on = StringField('Registered on', validators=[Length(min=0, max=140)], render_kw={'readonly': True}) |
| confirmed_on = StringField('Confirmed on', validators=[Length(min=0, max=140)], render_kw={'readonly': True}) |
| last_logged_in = StringField('Last logged in on', validators=[Length(min=0, max=140)], render_kw={'readonly': True}) |
| submit = SubmitField('Submit') |
| |
| def __init__(self, original_email, *args, **kwargs): |
| super(ProfileForm, self).__init__(*args, **kwargs) |
| self.original_email = original_email |
| |
| def validate_ssh_public_key(self, ssh_public_key): |
| if len(ssh_public_key.data) < 256 or len(ssh_public_key.data) > 1024: |
| raise ValidationError('Please enter valid SSH Public Key!') |