class SignInForm(flask_wtf.FlaskForm): email = wtforms.StringField( 'Email', [wtforms.validators.required()], filters=[util.email_filter], ) password = wtforms.StringField( 'Password', [wtforms.validators.required()], ) remember = wtforms.BooleanField( 'Keep me signed in', [wtforms.validators.optional()], ) recaptcha = flask_wtf.RecaptchaField() next_url = wtforms.HiddenField()
class LoginForm(flask_wtf.FlaskForm): username = wtforms.StringField( "Email", [wtforms.validators.DataRequired(), wtforms.validators.Email()] ) password = wtforms.PasswordField( "Password", [ wtforms.validators.DataRequired(), wtforms.validators.Length(max=password_max_length), ], ) time_zone = wtforms.HiddenField( "Timezone", [ wtforms.validators.DataRequired(), wtforms.validators.Length(min=tzdata_min_length, max=tzdata_max_length), ], ) recaptcha = flask_wtf.RecaptchaField()
class BugReportForm(flask_wtf.FlaskForm): report_type = wtforms.SelectField( "What kind of report are you submitting?", coerce=int, choices=[(k, v) for k, v in models.REPORT_TYPES.items()], validators=[ wtforms.validators.InputRequired(), ], ) text_response = wtforms.TextAreaField( "Description", validators=[ wtforms.validators.DataRequired(), ], render_kw={ "class": "form-control", "rows": 20, "style": "resize: vertical" }, ) recaptcha = flask_wtf.RecaptchaField() submit = wtforms.SubmitField() def validate(self): if not super(BugReportForm, self).validate(): return False user = None if flask_login.current_user.is_authenticated: user = flask_login.current_user bug_report = models.BugReport( user=user, report_type=self.report_type.data, text_response=self.text_response.data, ) db.session.add(bug_report) db.session.commit() return True
class ShareSecretForm(flask_wtf.FlaskForm): shortname = wtforms.StringField( "Secret shortname", validators=[ wtforms.validators.Optional(), wtforms.validators.Length(max=constants.SECRET_SHORTNAME_MAX_LEN), check_allowed_characters(constants.SECRET_SHORTNAME_CHARSET), ], render_kw={ "class": "form-control", "autocomplete": "off", "placeholder": constants.SECRET_SHORTNAME_PLACEHOLDER_TEXT, }, ) person = wtforms.StringField( "Your name", validators=[ wtforms.validators.DataRequired(), wtforms.validators.Length( max=constants.SECRET_PERSON_NAME_MAX_LEN), ], render_kw={ "class": "form-control", "autocomplete": "off" }, ) response = wtforms.StringField( "Your secret", validators=[ wtforms.validators.DataRequired(), wtforms.validators.Length(max=constants.SECRET_RESPONSE_MAX_LEN), ], render_kw={ "class": "form-control", "autocomplete": "off" }, ) expected_responses = wtforms.IntegerField( "How many *other* responses are expected?", ) recaptcha = flask_wtf.RecaptchaField() submit = wtforms.SubmitField() def __init__(self, secret, *args, **kwargs): super(ShareSecretForm, self).__init__(*args, **kwargs) self.secret = secret self.secret_response = None if secret is not None: del self.shortname del self.expected_responses def validate(self): if not super(ShareSecretForm, self).validate(): return False if self.secret is None and len(self.shortname.data) == 0: self.shortname.data = "".join( random.choice(tuple(constants.SECRET_SHORTNAME_CHARSET)) for _ in range(constants.SECRET_SHORTNAME_GEN_LEN)) if self.secret is None: self.secret = models.Secret.get_by_shortname(self.shortname.data) if self.secret is None: self.secret = models.Secret( shortname=self.shortname.data, # Add one for this user expected_responses=self.expected_responses.data + 1, ) db.session.add(self.secret) db.session.commit() # Don't allow submissions if the secret already has all required responses if self.secret.expected_responses == self.secret.actual_responses: # If the user clicked a direct link, shortname field is removed msg = "That secret already has all required responses" if self.shortname is not None: self.shortname.errors.append(msg) else: flask.flash( json.dumps({ "msg": msg, "link": flask.url_for("default.secret", secret_id=self.secret.id), }), "alert-warning", ) return False self.secret_response = models.SecretResponse( secret=self.secret, person=self.person.data, response=self.response.data, ) db.session.add(self.secret_response) db.session.commit() return True
class UserSignupForm(flask_wtf.FlaskForm): localpart = fields.StringField(_('Email address'), [validators.DataRequired(), validators.Regexp("^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+$")]) pw = fields.PasswordField(_('Password'), [validators.DataRequired()]) pw2 = fields.PasswordField(_('Confirm password'), [validators.EqualTo('pw')]) captcha = flask_wtf.RecaptchaField() submit = fields.SubmitField(_('Sign up'))
class ResetForm(flask_wtf.FlaskForm): username = wtforms.StringField( "Email", [wtforms.validators.DataRequired(), wtforms.validators.Email()] ) recaptcha = flask_wtf.RecaptchaField()
class UserSignupFormCaptcha(UserSignupForm): captcha = flask_wtf.RecaptchaField()
class InquiryForm(flask_wtf.Form): affiliation = AffiliationField("Affiliation", validators=[DataRequired()]) principal = PrincipalField("Email", validators=[DataRequired()]) message = TextAreaField("Message", validators=[DataRequired()]) recaptcha = flask_wtf.RecaptchaField() submit = SubmitField("Send Inquiry")
class UserSignupForm(flask_wtf.FlaskForm): localpart = fields.StringField(_('Email address'), [validators.DataRequired(), validators.Regexp(LOCALPART_REGEX)]) pw = fields.PasswordField(_('Password'), [validators.DataRequired()]) pw2 = fields.PasswordField(_('Confirm password'), [validators.EqualTo('pw')]) captcha = flask_wtf.RecaptchaField() submit = fields.SubmitField(_('Sign up'))