class RegistrationForm(wtforms.Form): def __init__(self, *args, **kwargs): super(RegistrationForm, self).__init__(*args, **kwargs) if 'site_key' in kwargs: self.captcha.public_key = kwargs.pop('site_key') else: raise ValueError('Recaptcha site key is required.') if 'secret_key' in kwargs: self.captcha.private_key = kwargs.pop('secret_key') else: raise ValueError('Recaptcha secret key is required.') username = wtforms.StringField( _('Username'), [wtforms.validators.InputRequired(), normalize_user_or_email_field(allow_email=False)]) password = wtforms.PasswordField( _('Password'), [wtforms.validators.InputRequired(), wtforms.validators.Length(min=5, max=1024)]) email = wtforms.StringField( _('Email address'), [wtforms.validators.InputRequired(), normalize_user_or_email_field(allow_user=False)]) captcha = RecaptchaField( public_key='unset', private_key='unset', secure=True)
def login(request): """ login(request) No return value Function called from route_url('apex_login', request) """ title = _('You need to login') came_from = get_came_from(request) if 'local' not in apex_settings('provider_exclude', []): if asbool(apex_settings('use_recaptcha_on_login')): if apex_settings('recaptcha_public_key') and apex_settings( 'recaptcha_private_key'): LoginForm.captcha = RecaptchaField( public_key=apex_settings('recaptcha_public_key'), private_key=apex_settings('recaptcha_private_key'), ) form = LoginForm( request.POST, captcha={'ip_address': request.environ['REMOTE_ADDR']}) else: form = LoginForm(request.POST) else: form = None velruse_forms = generate_velruse_forms(request, came_from) if request.method == 'POST' and form.validate(): user = AuthUser.get_by_username(form.data.get('username')) if user: headers = apex_remember(request, user.id) return HTTPFound(location=came_from, headers=headers) return {'title': title, 'form': form, 'velruse_forms': velruse_forms, \ 'form_url': request.route_url('apex_login'), 'action': 'login'}
class RegistrationForm(Form): username = TextField ('username', [validators.Length(max=25), validators.Required()]) password = PasswordField ('password', [validators.Length(min=4, max=25), validators.Required()]) confirm_password = PasswordField ('confirm_password', [validators.Required()]) submit = SubmitField ('submit') site_key = config.get("recaptcha", "public_key") secret_key = config.get("recaptcha", "private_key") captcha = RecaptchaField('recaptcha', public_key=site_key, private_key=secret_key, secure=True)
class ComplaintForm(Form): name = StringField('Full Name', validators=[DataRequired()]) email = EmailField('Email Address', validators=[DataRequired(), Email()]) phone = StringField('Phone Number', validators=[Optional()]) reason = StringField('Reason', validators=[DataRequired()], widget=widgets.TextArea()) captcha = RecaptchaField(public_key=app.config.get("RECAPTCHA_PUB_KEY"), private_key=app.config.get("RECAPTCHA_PRIV_KEY"), secure=True)
class FeedbackCaptchaForm(FeedbackForm): def __init__(self, public_key=None, private_key=None, *args, **kwargs): super(FeedbackCaptchaForm, self).__init__(*args, **kwargs) self.public_key = public_key self.private_key = private_key captcha = RecaptchaField( u'Введите указанный текст', secure=True )
class LoginForm(Form): """ The login form. """ username = TextField( 'Username', [validators.InputRequired(), validators.Length(min=1, max=80)]) password = PasswordField('Password', [validators.InputRequired()]) recaptcha = RecaptchaField() remember_me = BooleanField('Remember me')
def useradd(request): """ useradd(request) No return value Function called from route_url('apex_useradd', request) """ title = _('Create an user') velruse_forms = [] #This fixes the issue with RegisterForm throwing an UnboundLocalError if apex_settings('useradd_form_class'): UseraddForm = get_module(apex_settings('useradd_form_class')) else: from apex.forms import UseraddForm if 'local' not in apex_settings('provider_exclude', []): if asbool(apex_settings('use_recaptcha_on_register')): if apex_settings('recaptcha_public_key') and apex_settings( 'recaptcha_private_key'): UseraddForm.captcha = RecaptchaField( public_key=apex_settings('recaptcha_public_key'), private_key=apex_settings('recaptcha_private_key'), ) form = UseraddForm( request.POST, captcha={'ip_address': request.environ['REMOTE_ADDR']}) else: form = None if request.method == 'POST' and form.validate(): user = form.save() # on creation by an admin, the user must activate itself its account. begin_activation_email_process(request, user) DBSession.add(user) user.active = 'N' DBSession.flush() flash( _('User sucessfully created, An email has been sent ' 'to it\'s email to activate its account.'), 'success') return { 'title': title, 'form': form, 'velruse_forms': velruse_forms, 'action': 'useradd' }
def forgot_password(request): """ forgot_password(request): no return value, called with route_url('apex_forgot_password', request) """ title = _('Forgot my password') if asbool(apex_settings('use_recaptcha_on_forgot')): if apex_settings('recaptcha_public_key') and apex_settings( 'recaptcha_private_key'): ForgotForm.captcha = RecaptchaField( public_key=apex_settings('recaptcha_public_key'), private_key=apex_settings('recaptcha_private_key'), ) form = ForgotForm(request.POST, \ captcha={'ip_address': request.environ['REMOTE_ADDR']}) if request.method == 'POST' and form.validate(): """ Special condition - if email imported from OpenID/Auth, we can direct the person to the appropriate login through a flash message. """ if form.data['email']: user = AuthUser.get_by_email(form.data['email']) if user.login: provider_name = auth_provider.get(user.login[1], 'Unknown') flash(_('You used %s as your login provider' % \ provider_name)) return HTTPFound(location=route_url('apex_login', \ request)) if form.data['username']: user = AuthUser.get_by_username(form.data['username']) if user: timestamp = time.time() + 3600 hmac_key = hmac.new('%s:%s:%d' % (str(user.id), \ apex_settings('auth_secret'), timestamp), \ user.email).hexdigest()[0:10] time_key = base64.urlsafe_b64encode('%d' % timestamp) email_hash = '%s%s' % (hmac_key, time_key) apex_email_forgot(request, user.id, user.email, email_hash) flash(_('Password Reset email sent.')) return HTTPFound(location=route_url('apex_login', \ request)) flash(_('An error occurred, please contact the support team.')) return {'title': title, 'form': form, 'action': 'forgot'}
def login(request): """ login(request) No return value Function called from route_url('apex_login', request) """ title = _('You need to login') came_from = get_came_from(request) if apex_settings('login_form_class'): LoginForm = get_module(apex_settings('login_form_class')) else: from apex.forms import LoginForm if not apex_settings('exclude_local'): if asbool(apex_settings('use_recaptcha_on_login')): if apex_settings('recaptcha_public_key') and \ apex_settings('recaptcha_private_key'): LoginForm.captcha = RecaptchaField( public_key=apex_settings('recaptcha_public_key'), private_key=apex_settings('recaptcha_private_key'), ) form = LoginForm(request.POST, captcha={'ip_address': \ request.environ['REMOTE_ADDR']}) else: form = LoginForm(request.POST) else: form = None velruse_forms = generate_velruse_forms(request, came_from) if request.method == 'POST' and form.validate(): user = AuthUser.get_by_login(form.data.get('login')) if user: headers = apex_remember(request, user, \ max_age=apex_settings('max_cookie_age', None)) return HTTPFound(location=came_from, headers=headers) return {'title': title, 'form': form, 'velruse_forms': velruse_forms, \ 'form_url': request.route_url('apex_login'), 'action': 'login'}
class RegistrationForm(FlaskForm): first_name = StringField( 'First Name', validators=[DataRequired(), Length(min=2, max=40)]) last_name = StringField('Last Name', validators=[DataRequired(), Length(min=2, max=40)]) email = StringField( 'Email', validators=[DataRequired(), Email(), Length(min=6, max=40)]) username = StringField('Username', validators=[DataRequired(), Length(min=4, max=40)]) password = PasswordField( 'New Password', [DataRequired(), EqualTo('confirm', message='Passwords must match')]) confirm = PasswordField('Repeat Password') captcha = RecaptchaField(public_key=app.config['RECAPTCHA_PUB_KEY'], private_key=app.config['RECAPTCHA_PRIV_KEY'], secure=True)
def add_auth(request): title = _('Add another Authentication method') came_from = request.params.get('came_from', \ route_url(apex_settings('came_from_route'), request)) auth_id = authenticated_userid(request) request.session['id'] = auth_id auth_providers = apex_id_providers(auth_id) exclude = set([]) if not apex_settings('allow_duplicate_providers'): exclude = set([x.split('.')[0] for x in auth_providers]) velruse_forms = generate_velruse_forms(request, came_from, exclude) #This fixes the issue with RegisterForm throwing an UnboundLocalError if apex_settings('auth_form_class'): AddAuthForm = get_module(apex_settings('auth_form_class')) else: from apex.forms import AddAuthForm form = None if not apex_settings('exclude_local') and 'local' not in exclude: if not asbool(apex_settings('use_recaptcha_on_auth')): if apex_settings('recaptcha_public_key') and \ apex_settings('recaptcha_private_key'): AddAuthForm.captcha = RecaptchaField( public_key=apex_settings('recaptcha_public_key'), private_key=apex_settings('recaptcha_private_key'), ) form = AddAuthForm(request.POST, captcha={'ip_address': \ request.environ['REMOTE_ADDR']}) if request.method == 'POST' and form.validate(): form.save(auth_id) return HTTPFound(location=came_from) return {'title': title, 'form': form, 'velruse_forms': velruse_forms, \ 'action': 'add_auth'}
def register(request): """ register(request): no return value, called with route_url('apex_register', request) """ title = _('Register') came_from = request.params.get('came_from', \ route_url(apex_settings('came_from_route'), request)) velruse_forms = generate_velruse_forms(request, came_from) #This fixes the issue with RegisterForm throwing an UnboundLocalError if apex_settings('register_form_class'): RegisterForm = get_module(apex_settings('register_form_class')) else: from apex.forms import RegisterForm if 'local' not in apex_settings('provider_exclude', []): if asbool(apex_settings('use_recaptcha_on_register')): if apex_settings('recaptcha_public_key') and apex_settings( 'recaptcha_private_key'): RegisterForm.captcha = RecaptchaField( public_key=apex_settings('recaptcha_public_key'), private_key=apex_settings('recaptcha_private_key'), ) form = RegisterForm( request.POST, captcha={'ip_address': request.environ['REMOTE_ADDR']}) else: form = None if request.method == 'POST' and form.validate(): user = form.save() headers = apex_remember(request, user.id) return HTTPFound(location=came_from, headers=headers) return {'title': title, 'form': form, 'velruse_forms': velruse_forms, \ 'action': 'register'}
def reset_password(request): """ reset_password(request): no return value, called with route_url('apex_reset_password', request) """ title = _('Reset My Password') if asbool(apex_settings('use_recaptcha_on_reset')): if apex_settings('recaptcha_public_key') and \ apex_settings('recaptcha_private_key'): ResetPasswordForm.captcha = RecaptchaField( public_key=apex_settings('recaptcha_public_key'), private_key=apex_settings('recaptcha_private_key'), ) form = ResetPasswordForm(request.POST, \ captcha={'ip_address': request.environ['REMOTE_ADDR']}) if request.method == 'POST' and form.validate(): user_id = request.matchdict.get('user_id') user = AuthUser.get_by_id(user_id) submitted_hmac = request.matchdict.get('hmac') current_time = time.time() time_key = int(base64.b64decode(submitted_hmac[10:])) if current_time < time_key: hmac_key = hmac.new('%s:%s:%d' % (str(user.id), \ apex_settings('auth_secret'), time_key), \ user.email).hexdigest()[0:10] if hmac_key == submitted_hmac[0:10]: #FIXME reset email, no such attribute email user.password = form.data['password'] DBSession.merge(user) DBSession.flush() flash(_('Password Changed. Please log in.')) return HTTPFound(location=route_url('apex_login', \ request)) else: flash(_('Invalid request, please try again')) return HTTPFound(location=route_url('apex_forgot', \ request)) return {'title': title, 'form': form, 'action': 'reset'}
class DefinitionForm(Form): captcha = RecaptchaField(public_key=RECAPTCHA_PUB_KEY, private_key=RECAPTCHA_PRIV_KEY, secure=True) entry = TextField('Termino*', [ validate_entry, validators.Length( message=u'Debe tener entre 3 y 50 caractacteres.', min=3, max=50, ) ]) definition = TextAreaField('Definición*', [ validators.Length( message=u'Debe tener entre 15 y 300 caracteres.', min=15, max=300) ]) example = TextAreaField('Ejemplo (Opcional)', [ validators.Length( message=u'No puede tener mas de 300 caracteres', min=0, max=300) ])
class RegistrationForm(Form): "Simple Registration form" def _get_translations(self): """ Provide alternate translations factory. """ return get_translations() name = TextField(_('Name'), [ validators.Required(), ]) email = TextField(_('e-mail'), [validators.Required(), validators.Email()]) password = PasswordField(_('New Password'), [ validators.Required(), validators.EqualTo('confirm', message=_('Passwords must match')) ]) confirm = PasswordField(_('Confirm Password')) if 're_captcha_public' in CONFIG.options: captcha = RecaptchaField( public_key=CONFIG.options['re_captcha_public'], private_key=CONFIG.options['re_captcha_private'], secure=True)
class RegisterForm(Form): username = TextField('Username', validators=[ validators.Required(), validators.Length(min=3, max=8), validators.UniqueColumn( database.User, database.User.username, message='This username is taken.') ]) password = PasswordField('Password', validators=[ validators.Required(), validators.Length(min=8, max=50), validators.CrackLib() ]) first_name = TextField('First Name', validators=[validators.Required()]) last_name = TextField('Last Name', validators=[validators.Required()]) pw_confirm = PasswordField('Confirm Password', validators=[ validators.Required(), validators.Length(min=8, max=50), validators.EqualTo( 'password', message='Passwords do not match.') ]) dob = TextField('Date of Birth (MM/DD/YYYY)', validators=[ validators.Required(), validators.Date( format='%m/%d/%Y', message='Invalid format. Please use mm/dd/yyyy.') ]) email = TextField( 'E-mail Address', validators=[ validators.Email(), validators.Required(), validators.UniqueColumn( database.User, database.User.email, message='This e-mail is in use by another account.') ]) sponsor = SelectField('Sponsor', choices=[(s.username, ''.join( (s.last_name, ', ', s.first_name))) for s in database.get_sponsors()], validators=[validators.Required()]) grad_date = TextField('Graduation Date (MM/YYYY)', validators=[ validators.Required(), validators.Date( format='%m/%Y', message='Invalid format. Please use mm/yyyy') ]) description = TextAreaField('Description of Usage') acct_type = RadioField(choices=[('acad', 'Academic'), ('research', 'Research & Academic')], validators=[validators.Required()]) captcha = RecaptchaField( public_key='6LdeFcwSAAAAAJF1ccPQ4j5Y0Q0iVULdXpRArpcp', private_key='6LdeFcwSAAAAAFv_xLOVLCPAyUQ_abubmG8oUdOw', secure=True)
def login(request): """ login(request) No return value Function called from route_url('apex_login', request) """ if request.user: if 'came_from' in request.params: return HTTPFound(location=request.params['came_from']) title = _('You need to login') came_from = get_came_from(request) velruse_forms = generate_velruse_forms(request, came_from) providers = get_providers() use_captcha = asbool(apex_settings('use_recaptcha_on_login')) if 'local' not in apex_settings('provider_exclude', []): if use_captcha: if apex_settings('recaptcha_public_key') and apex_settings( 'recaptcha_private_key'): LoginForm.captcha = RecaptchaField( public_key=apex_settings('recaptcha_public_key'), private_key=apex_settings('recaptcha_private_key'), ) form = LoginForm( request.POST, captcha={'ip_address': request.environ['REMOTE_ADDR']}) else: form = None for vform in velruse_forms: if getattr(vform, 'velruse_login', None): vform.action = vform.velruse_login # allow to include this as a portlet inside other pages if (request.method == 'POST' and (request.route_url('apex_login') in request.url)): local_status = form.validate() username = form.data.get('username') password = form.data.get('password') user = search_user(username) if local_status and user: if user.active == 'Y': headers = apex_remember(request, user.id, internal_user=True) return HTTPFound(location=came_from, headers=headers) else: stop = False if use_captcha: if 'captcha' in form.errors: stop = True form.came_from.data = came_from form.data['came_from'] = came_from if not stop: end_point = '%s?%s' % ( request.route_url('apex_callback'), urlencode( dict( csrf_token=request.session.get_csrf_token(), came_from=came_from, ))) # try ldap auth if present on velruse # idea is to let the browser to the request with # an autosubmitted form if 'velruse.providers.ldapprovider' in providers: response = AUTOSUBMITED_VELRUSE_LDAP_FORM % ( providers['velruse.providers.ldapprovider']['login'], end_point, username, password) return Response(response) if not came_from: came_from = request.url form.came_from.data = came_from return { 'title': title, 'form': form, 'velruse_forms': velruse_forms, 'form_url': request.route_url('apex_login'), 'action': 'login' }
class CaptchaForm(Form): captcha = RecaptchaField(public_key='testpub', private_key='testpriv', validators = [RecaptchaSuccessfulValidatorMockup()])
def register(request): """ register(request): no return value, called with route_url('apex_register', request) """ title = _('Register') came_from = request.params.get('came_from', \ route_url(apex_settings('came_from_route'), request)) velruse_forms = generate_velruse_forms(request, came_from) #This fixes the issue with RegisterForm throwing an UnboundLocalError if apex_settings('register_form_class'): RegisterForm = get_module(apex_settings('register_form_class')) else: from apex.forms import RegisterForm if 'local' not in apex_settings('provider_exclude', []): if asbool(apex_settings('use_recaptcha_on_register')): if apex_settings('recaptcha_public_key') and apex_settings( 'recaptcha_private_key'): RegisterForm.captcha = RecaptchaField( public_key=apex_settings('recaptcha_public_key'), private_key=apex_settings('recaptcha_private_key'), ) form = RegisterForm( request.POST, captcha={'ip_address': request.environ['REMOTE_ADDR']}) else: form = None if request.method == 'POST' and form.validate(): user = form.save() need_verif = apex_settings('need_mail_verification') response = HTTPFound(location=came_from) if need_verif: try: DBSession.add(user) except: pass begin_activation_email_process(request, user) user.active = 'N' DBSession.flush() flash( _('User sucessfully created, ' 'please verify your account by clicking ' 'on the link in the mail you just received from us !'), 'success') response = HTTPFound(location=came_from) else: transaction.commit() headers = apex_remember(request, user.id, internal_user=True) response = HTTPFound(location=came_from, headers=headers) return response return { 'title': title, 'form': form, 'velruse_forms': velruse_forms, 'action': 'register' }
class TrollForm(Form): name = TextField(u'name', default='anonymous') content = TextAreaField(u'content', [validators.required]) captcha = RecaptchaField(public_key=PUBLIC_KEY, private_key=PRIVATE_KEY)
class CaptchaForm(Form): captcha = RecaptchaField(public_key='testpub', private_key='testpriv', validators = [RecaptchaInternalFailedValidatorMockup()])
class CaptchaForm(Form): captcha = RecaptchaField()
class CaptchaForm(Form): captcha = RecaptchaField(public_key='testpub', private_key='testpriv')