def get_registration_form(request): random_pw = get_random_password() if 'random' in request.args else None class RegistrationForm(Form): username = TextField( lazy_gettext(u'Username'), [validators.required(), validators.is_user(negative=True)]) email = TextField(lazy_gettext(u'Email'), [ validators.required(), validators.is_user(negative=True, key='email') ]) password = PasswordField(lazy_gettext(u'Password'), [ validators.required(), validators.equal_to('confirm', message=lazy_gettext(u'Passwords must match')) ], widget=widgets.PasswordInput(False), default=random_pw) confirm = PasswordField(lazy_gettext(u'Repeat Passord'), [validators.required()], widget=widgets.PasswordInput(False), default=random_pw) captcha = RecaptchaField(lazy_gettext(u'ReCaptcha')) return RegistrationForm
def get_change_password_form(request): random_pw = get_random_password() if 'random' in request.args else None class ChangePasswordForm(Form): old_password = PasswordField(lazy_gettext(u'Old Password'), [validators.required()]) new_password = PasswordField(lazy_gettext(u'New Password'), [validators.required()], default=random_pw, widget=widgets.PasswordInput(False)) new_password_confirm = PasswordField(lazy_gettext(u'New Password (confirmation)'), [validators.equal_to('new_password', message=lazy_gettext(u'Passwords must match'))], default=random_pw, widget=widgets.PasswordInput(False)) return ChangePasswordForm
def get_registration_form(request): random_pw = get_random_password() if 'random' in request.args else None class RegistrationForm(Form): username = TextField(lazy_gettext(u'Username'), [validators.required(), validators.is_user(negative=True)]) email = TextField(lazy_gettext(u'Email'), [validators.required(), validators.is_user(negative=True, key='email')]) password = PasswordField(lazy_gettext(u'Password'), [validators.required(), validators.equal_to('confirm', message=lazy_gettext(u'Passwords must match'))], widget=widgets.PasswordInput(False), default=random_pw) confirm = PasswordField(lazy_gettext(u'Repeat Passord'), [validators.required()], widget=widgets.PasswordInput(False), default=random_pw) captcha = RecaptchaField(lazy_gettext(u'ReCaptcha')) return RegistrationForm
def get_change_password_form(request): random_pw = get_random_password() if 'random' in request.args else None class ChangePasswordForm(Form): old_password = PasswordField(lazy_gettext(u'Old Password'), [validators.required()]) new_password = PasswordField(lazy_gettext(u'New Password'), [validators.required()], default=random_pw, widget=widgets.PasswordInput(False)) new_password_confirm = PasswordField( lazy_gettext(u'New Password (confirmation)'), [ validators.equal_to( 'new_password', message=lazy_gettext(u'Passwords must match')) ], default=random_pw, widget=widgets.PasswordInput(False)) return ChangePasswordForm
def get_random_password(self, request): return {'password': get_random_password()}