def __init__(self, request=None, *args, **kwargs): self.request = request self.standalone = kwargs.pop('standalone') self.signer = signing.TimestampSigner(salt=f'customer-registration-captcha-{get_client_ip(request)}') super().__init__(*args, **kwargs) event = getattr(request, "event", None) if event and event.settings.order_phone_asked: if event.settings.region or event.organizer.settings.region: country_code = event.settings.region or event.organizer.settings.region phone_prefix = get_phone_prefix(country_code) if phone_prefix: self.initial['phone'] = "+{}.".format(phone_prefix) self.fields['phone'] = PhoneNumberField( label=_('Phone'), required=event.settings.order_phone_required, widget=WrappedPhoneNumberPrefixWidget() ) self.fields['name_parts'] = NamePartsFormField( max_length=255, required=True, scheme=request.organizer.settings.name_scheme, titles=request.organizer.settings.name_scheme_titles, label=_('Name'), ) if self.standalone: # In the setandalone registration form, we add a simple CAPTCHA. We don't expect # this to actually turn away and motivated attacker, it's mainly a protection # against spam bots looking for contact forms. Since the standalone registration # form is one of the simplest public forms we have in the application it is the # most common target for untargeted bots. a = random.randint(1, 9) b = random.randint(1, 9) if 'challenge' in self.data: try: a, b = self.signer.unsign(self.data.get('challenge'), max_age=3600).split('+') a, b = int(a), int(b) except: pass self.fields['challenge'] = forms.CharField( widget=forms.HiddenInput, initial=self.signer.sign(f'{a}+{b}') ) self.fields['response'] = forms.IntegerField( label=_('What is the result of {num1} + {num2}?').format( num1=a, num2=b, ), min_value=0, )
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if not self.instance.phone and (self.instance.organizer.settings.region or self.instance.locale): country_code = self.instance.organizer.settings.region or get_country_by_locale( self.instance.locale) phone_prefix = get_phone_prefix(country_code) if phone_prefix: self.initial['phone'] = "+{}.".format(phone_prefix) self.fields['phone'] = PhoneNumberField( label=_('Phone'), required=False, widget=WrappedPhoneNumberPrefixWidget()) self.fields['name_parts'] = NamePartsFormField( max_length=255, required=False, scheme=self.instance.organizer.settings.name_scheme, titles=self.instance.organizer.settings.name_scheme_titles, label=_('Name'), )
def __init__(self, request=None, *args, **kwargs): self.request = request super().__init__(*args, **kwargs) event = getattr(request, "event", None) if event and event.settings.order_phone_asked: if event.settings.region or event.organizer.settings.region: country_code = event.settings.region or event.organizer.settings.region phone_prefix = get_phone_prefix(country_code) if phone_prefix: self.initial['phone'] = "+{}.".format(phone_prefix) self.fields['phone'] = PhoneNumberField( label=_('Phone'), required=event.settings.order_phone_required, widget=WrappedPhoneNumberPrefixWidget()) self.fields['name_parts'] = NamePartsFormField( max_length=255, required=True, scheme=request.organizer.settings.name_scheme, titles=request.organizer.settings.name_scheme_titles, label=_('Name'), )