class AuthenticationForm(auth_forms.AuthenticationForm): username = forms.CharField(max_length=75, widget=RequiredEmailInput) password = forms.CharField(max_length=255, min_length=PasswordMixin.min_length, error_messages=PasswordMixin.error_msg, widget=PasswordMixin.widget(render_value=False, required=True)) rememberme = forms.BooleanField(required=False) recaptcha = ReCaptchaField() recaptcha_shown = forms.BooleanField(widget=forms.HiddenInput, required=False) def __init__(self, request=None, use_recaptcha=False, *args, **kw): super(AuthenticationForm, self).__init__(*args, **kw) if not use_recaptcha or not settings.NOBOT_RECAPTCHA_PRIVATE_KEY: del self.fields['recaptcha'] def clean(self): # We want an explicit error message for old accounts with a too # short password, see bug 1067673 for details. if ('password' in self.errors and 'password' in self.data and 1 < len(self.data['password']) < PasswordMixin.min_length): msg = _( 'As part of our new password policy, your password must ' 'be %s characters or more. Please update your password by ' '<a href="%s">issuing a password reset</a>.') % ( PasswordMixin.min_length, reverse('password_reset_form')) self._errors['password'] = ErrorList([mark_safe(msg)]) # Only clean the form (username and password) if recaptcha is ok. if 'recaptcha' in self.errors: return {} return super(AuthenticationForm, self).clean()
class AgreementForm(forms.Form): distribution_agreement = forms.BooleanField() review_policy = forms.BooleanField() recaptcha = ReCaptchaField(label='') def __init__(self, *args, **kwargs): super(AgreementForm, self).__init__(*args, **kwargs) if not waffle.switch_is_active('developer-agreement-captcha'): del self.fields['recaptcha']
class AbuseForm(happyforms.Form): recaptcha = ReCaptchaField(label='') text = forms.CharField(required=True, label='', widget=forms.Textarea()) def __init__(self, *args, **kwargs): self.request = kwargs.pop('request') super(AbuseForm, self).__init__(*args, **kwargs) if (not self.request.user.is_anonymous() or not settings.NOBOT_RECAPTCHA_PRIVATE_KEY): del self.fields['recaptcha']
class AgreementForm(forms.Form): distribution_agreement = forms.BooleanField() review_policy = forms.BooleanField() recaptcha = ReCaptchaField(label='') def __init__(self, *args, **kwargs): render_captcha = kwargs.pop('render_captcha', False) super(AgreementForm, self).__init__(*args, **kwargs) if not render_captcha: del self.fields['recaptcha']
class UserRegisterForm(happyforms.ModelForm, UsernameMixin): """ For registering users. We're not building off d.contrib.auth.forms.UserCreationForm because it doesn't do a lot of the details here, so we'd have to rewrite most of it anyway. """ username = forms.CharField(max_length=50, required=False) email = forms.EmailField(widget=RequiredEmailInput) display_name = forms.CharField(label=_lazy(u'Display Name'), max_length=50, required=False) location = forms.CharField(label=_lazy(u'Location'), max_length=100, required=False) occupation = forms.CharField(label=_lazy(u'Occupation'), max_length=100, required=False) recaptcha = ReCaptchaField() homepage = HttpHttpsOnlyURLField(label=_lazy(u'Homepage'), required=False) class Meta: model = UserProfile fields = ('username', 'display_name', 'location', 'occupation', 'recaptcha', 'homepage', 'email') def __init__(self, *args, **kwargs): instance = kwargs.get('instance') if instance and instance.has_anonymous_username(): kwargs.setdefault('initial', {}) kwargs['initial']['username'] = '' super(UserRegisterForm, self).__init__(*args, **kwargs) if not settings.NOBOT_RECAPTCHA_PRIVATE_KEY: del self.fields['recaptcha'] errors = { 'invalid': _('This URL has an invalid format. ' 'Valid URLs look like ' 'http://example.com/my_page.') } self.fields['homepage'].error_messages = errors def clean_display_name(self): name = self.cleaned_data['display_name'] if BlacklistedName.blocked(name): raise forms.ValidationError(_('This display name cannot be used.')) return name
class UserRegisterForm(happyforms.ModelForm, UsernameMixin, PasswordMixin): """ For registering users. We're not building off d.contrib.auth.forms.UserCreationForm because it doesn't do a lot of the details here, so we'd have to rewrite most of it anyway. """ username = forms.CharField(max_length=50, required=False) email = forms.EmailField(widget=RequiredEmailInput) display_name = forms.CharField(label=_lazy(u'Display Name'), max_length=50, required=False) location = forms.CharField(label=_lazy(u'Location'), max_length=100, required=False) occupation = forms.CharField(label=_lazy(u'Occupation'), max_length=100, required=False) password = forms.CharField(max_length=255, min_length=PasswordMixin.min_length, error_messages=PasswordMixin.error_msg, widget=PasswordMixin.widget(render_value=False, required=True)) password2 = forms.CharField(max_length=255, widget=PasswordMixin.widget(render_value=False, required=True)) recaptcha = ReCaptchaField() homepage = HttpHttpsOnlyURLField(label=_lazy(u'Homepage'), required=False) class Meta: model = UserProfile fields = ('username', 'display_name', 'location', 'occupation', 'password', 'password2', 'recaptcha', 'homepage', 'email') def __init__(self, *args, **kwargs): instance = kwargs.get('instance') if instance and instance.has_anonymous_username(): kwargs.setdefault('initial', {}) kwargs['initial']['username'] = '' super(UserRegisterForm, self).__init__(*args, **kwargs) if not settings.NOBOT_RECAPTCHA_PRIVATE_KEY: del self.fields['recaptcha'] errors = { 'invalid': _('This URL has an invalid format. ' 'Valid URLs look like ' 'http://example.com/my_page.') } self.fields['homepage'].error_messages = errors def clean_email(self): d = self.cleaned_data['email'].split('@')[-1] if BlacklistedEmailDomain.blocked(d): raise forms.ValidationError( _('Please use an email address from a ' 'different provider to complete ' 'your registration.')) return self.cleaned_data['email'] def clean_display_name(self): name = self.cleaned_data['display_name'] if BlacklistedName.blocked(name): raise forms.ValidationError(_('This display name cannot be used.')) return name def clean(self): super(UserRegisterForm, self).clean() data = self.cleaned_data # Passwords p1 = data.get('password') p2 = data.get('password2') # If p1 is invalid because its blocked, this message is non sensical. if p1 and p1 != p2: msg = _('The passwords did not match.') self._errors['password2'] = ErrorList([msg]) if p2: del data['password2'] return data