Пример #1
0
class DynamicLoginForm(forms.Form):
    mobile = forms.CharField(required=True, min_length=11, max_length=11)
    captcha = CaptchaField()
Пример #2
0
class ForgetForm(forms.Form):
    email = forms.EmailField(required=True)
    captcha = CaptchaField(error_messages={"invalid": u"验证码错误"})
Пример #3
0
class CaptchaForm(forms.Form):
    captcha = CaptchaField()
Пример #4
0
from captcha.fields import CaptchaField
Пример #5
0
class CaptchaTestForm(forms.Form):
    email = EmailField(required=True,
                       error_messages={'required': '必须填写邮箱'},
                       label='邮箱')
    captcha = CaptchaField()
Пример #6
0
    def __init__(self, form, user, *args, **kwargs):
        """
        Dynamically add each of the form fields for the given form model
        instance and its related field model instances.
        """
        self.user = user
        self.form = form
        self.form_fields = form.fields.visible().order_by('position')
        self.auto_fields = form.fields.auto_fields().order_by('position')
        super(FormForForm, self).__init__(*args, **kwargs)

        def add_fields(form, form_fields):
            for field in form_fields:
                field_key = "field_%s" % field.id
                if "/" in field.field_type:
                    field_class, field_widget = field.field_type.split("/")
                else:
                    field_class, field_widget = field.field_type, None

                if field.field_type == 'EmailVerificationField':
                    one_email = get_setting('module', 'forms', 'one_email')
                    if one_email:
                        field_class = forms.EmailField
                    else:
                        field_class = EmailVerificationField

                elif field.field_type == 'BooleanField' and len(
                        field.choices) > 0:
                    field_class = forms.MultipleChoiceField
                    field_widget = 'django.forms.CheckboxSelectMultiple'

                elif field.field_type == 'CountryField':
                    field_class = CountrySelectField
                elif field.field_type == 'StateProvinceField':
                    field_class = getattr(forms, 'ChoiceField')
                else:
                    field_class = getattr(forms, field_class)
                field_args = {
                    "label": mark_safe(field.label),
                    "required": field.required
                }
                arg_names = field_class.__init__.im_func.func_code.co_varnames
                if "max_length" in arg_names:
                    field_args["max_length"] = FIELD_MAX_LENGTH
                if "choices" in arg_names and field.field_type != 'CountryField':
                    field_args["choices"] = field.get_choices()
                    #field_args["choices"] = zip(choices, choices)
                if "initial" in arg_names:
                    default = field.default.lower()
                    if field_class == "BooleanField":
                        if default == "checked" or default == "true" or \
                            default == "on" or default == "1":
                            default = True
                        else:
                            default = False
                    field_args["initial"] = field.default

                if field_widget is not None:
                    module, widget = field_widget.rsplit(".", 1)
                    field_args["widget"] = getattr(import_module(module),
                                                   widget)

                if field.field_function == 'EmailFirstName':
                    field_args["max_length"] = FIELD_FNAME_LENGTH
                elif field.field_function == 'EmailLastName':
                    field_args["max_length"] = FIELD_LNAME_LENGTH
                elif field.field_function == 'EmailFullName':
                    field_args["max_length"] = FIELD_NAME_LENGTH
                elif field.field_function == 'EmailPhoneNumber':
                    field_args["max_length"] = FIELD_PHONE_LENGTH
                elif field.field_type == 'FileField':
                    field_args["validators"] = [FileValidator()]

                form.fields[field_key] = field_class(**field_args)

                if not field_class == EmailVerificationField:
                    form.fields[field_key].widget.attrs['title'] = field.label
                    form.fields[field_key].widget.attrs[
                        'class'] = 'formforform-field'
                else:
                    form.fields[field_key].widget.widgets[0].attrs[
                        'class'] += ' formforform-field'
                    form.fields[field_key].widget.widgets[1].attrs[
                        'class'] += ' formforform-field'
                widget_name = form.fields[
                    field_key].widget.__class__.__name__.lower()
                if widget_name == 'selectdatewidget':
                    form.fields[field_key].widget.years = range(
                        1920, THIS_YEAR + 10)
                if widget_name in ('dateinput', 'selectdatewidget',
                                   'datetimeinput'):
                    form.fields[field_key].initial = datetime.now()

        def add_pricing_fields(form, formforform):
            # include pricing options if any
            if (formforform.custom_payment or formforform.recurring_payment
                ) and formforform.pricing_set.all():

                currency_symbol = get_setting('site', 'global',
                                              'currencysymbol')

                pricing_options = []
                for pricing in formforform.pricing_set.all():

                    if pricing.price is None:
                        pricing_options.append((
                            pricing.pk,
                            mark_safe(
                                '<input type="text" class="custom-price" name="custom_price_%s" value="%s"/> <strong>%s</strong><br>%s'
                                %
                                (pricing.pk,
                                 form.data.get('custom_price_%s' % pricing.pk,
                                               unicode()), pricing.label,
                                 pricing.description))))
                    else:
                        if formforform.recurring_payment:
                            pricing_options.append(
                                (pricing.pk,
                                 mark_safe(
                                     '<strong>%s per %s %s - %s</strong><br>%s'
                                     % (tcurrency(pricing.price),
                                        pricing.billing_frequency,
                                        pricing.billing_period, pricing.label,
                                        pricing.description))))
                        else:
                            pricing_options.append(
                                (pricing.pk,
                                 mark_safe(
                                     '<strong>%s %s</strong><br>%s' %
                                     (tcurrency(pricing.price), pricing.label,
                                      pricing.description))))

                form.fields['pricing_option'] = forms.ChoiceField(
                    label=_('Pricing'),
                    choices=pricing_options,
                    widget=forms.RadioSelect(attrs={'class': 'pricing-field'}))

                form.fields['payment_option'] = forms.ModelChoiceField(
                    label=_('Payment Method'),
                    empty_label=None,
                    queryset=formforform.payment_methods.all(),
                    widget=forms.RadioSelect(attrs={'class': 'payment-field'}),
                    initial=1,
                )

        if self.form.pricing_position < self.form.fields_position:
            add_pricing_fields(self, self.form)
            add_fields(self, self.form_fields)
        else:
            add_fields(self, self.form_fields)
            add_pricing_fields(self, self.form)

        if not self.user.is_authenticated() and get_setting(
                'site', 'global', 'captcha'):  # add captcha if not logged in
            self.fields['captcha'] = CaptchaField(
                label=_('Type the code below'))

        self.add_form_control_class()
Пример #7
0
class CaptchaForm(forms.Form):

    verification_code = CaptchaField()
Пример #8
0
class ForgetForm(forms.Form):

    email = forms.EmailField(required=True)
    captcha = CaptchaField(error_messages={"invalid": "The code you enter is invalid!"})
class BlogForm(forms.ModelForm):
    captcha = CaptchaField()

    class Meta:
        model = Blog
        fields = '__all__'
Пример #10
0
class UserForgetForm(forms.Form):
    # 自动验证是否是邮箱格式
    email = forms.EmailField(required=True)
    # 使用验证码
    captcha = CaptchaField()
Пример #11
0
class RegisterForm(forms.Form):
    '''注册验证表单'''
    email = forms.EmailField(required=True)
    password = forms.CharField(required=True,min_length=5)
    # 验证码,字段里面可以自定义错误提示信息
    captcha = CaptchaField()
Пример #12
0
class ForgetForm(forms.Form):
    """
        忘记密码表单
    """
    email = forms.EmailField(required=True)
    captcha = CaptchaField(error_messages={'invalid': '验证码错误!'})
Пример #13
0
class SignUpForm(UserCreationForm):
    birth_date = forms.DateField(
        help_text='Required. Format: YYYY-MM-DD',
        widget=forms.TextInput(attrs={
            'placeholder': 'DOB',
            'class': 'form-control',
            'style': 'width:200px'
        }))
    gender = forms.ChoiceField(
        choices=GENDER,
        required=True,
        widget=forms.Select(attrs={
            'class': 'dropdown-item',
            'style': 'width:200px'
        }))
    status = forms.ChoiceField(
        choices=STATUS,
        required=True,
        widget=forms.Select(attrs={
            'class': 'dropdown-item',
            'style': 'width:200px'
        }))
    referal_id = forms.CharField(
        help_text=
        '(make sure you enter it right because this cannot be changed later)',
        required=False,
        widget=forms.TextInput(
            attrs={
                'placeholder': 'Referal_id',
                'class': 'form-control',
                'style': 'width:200px'
            }))
    pan_number = forms.IntegerField(required=True,
                                    max_value=9999999999,
                                    widget=forms.NumberInput(
                                        attrs={
                                            'placeholder': 'Pan Number',
                                            'class': 'form-control',
                                            'style': 'width:200px'
                                        }))
    address = forms.CharField(required=True,
                              widget=forms.TextInput(
                                  attrs={
                                      'placeholder': 'Address',
                                      'class': 'form-control',
                                      'style': 'width:200px'
                                  }))
    city = forms.CharField(
        required=True,
        widget=forms.TextInput(attrs={
            'placeholder': 'City',
            'class': 'form-control',
            'style': 'width:200px'
        }))
    pincode = forms.IntegerField(required=True,
                                 max_value=999999,
                                 widget=forms.NumberInput(
                                     attrs={
                                         'placeholder': 'Pincode',
                                         'class': 'form-control',
                                         'style': 'width:200px'
                                     }))
    email = forms.EmailField(help_text='must be unique',
                             required=True,
                             widget=forms.EmailInput(
                                 attrs={
                                     'placeholder': 'E-Mail',
                                     'class': 'form-control',
                                     'style': 'width:200px'
                                 }))
    mobile_number = forms.IntegerField(help_text='must be unique',
                                       required=True,
                                       max_value=9999999999,
                                       widget=forms.NumberInput(
                                           attrs={
                                               'placeholder': 'Mobile Number',
                                               'class': 'form-control',
                                               'style': 'width:200px'
                                           }))
    state = forms.CharField(required=True,
                            widget=forms.TextInput(
                                attrs={
                                    'placeholder': 'State',
                                    'class': 'form-control',
                                    'style': 'width:200px'
                                }))
    password1 = forms.CharField(widget=forms.PasswordInput(
        attrs={
            'placeholder': 'Password',
            'class': 'form-control',
            'style': 'width:200px'
        }),
                                label="Password",
                                required=True)
    password2 = forms.CharField(widget=forms.PasswordInput(
        attrs={
            'placeholder': 'Confirm Password',
            'class': 'form-control',
            'style': 'width:200px'
        }),
                                label="Confirm Password",
                                required=True)
    username = forms.CharField(widget=forms.TextInput(
        attrs={
            'placeholder': 'Username',
            'class': 'form-control',
            'style': 'width:200px'
        }),
                               label="Username",
                               required=True)
    first_name = forms.CharField(required=True,
                                 widget=forms.TextInput(
                                     attrs={
                                         'placeholder': 'First Name',
                                         'class': 'form-control',
                                         'style': 'width:200px'
                                     }))
    last_name = forms.CharField(required=False,
                                widget=forms.TextInput(
                                    attrs={
                                        'placeholder': 'Last Name',
                                        'class': 'form-control',
                                        'style': 'width:200px'
                                    }))
    captcha = CaptchaField()
    profile_pic = forms.FileField(required=False)

    def clean_email(self):
        mail = self.cleaned_data['email']
        try:
            match = User.objects.get(email__iexact=mail)
        except:
            return mail
        raise forms.ValidationError("Email already exists.")

    def clean_mobile_number(self):
        m_num = self.cleaned_data['mobile_number']
        try:
            match = Profile.objects.get(mobile_number__iexact=m_num)
        except:
            return m_num
        raise forms.ValidationError('Mobile Number already exist...Try Again!')

    class Meta:
        model = User
        fields = (
            'referal_id',
            'username',
            'first_name',
            'last_name',
            'pan_number',
            'gender',
            'birth_date',
            'status',
            'address',
            'city',
            'pincode',
            'state',
            'mobile_number',
            'email',
            'profile_pic',
            'password1',
            'password2',
            'captcha',
        )
Пример #14
0
class CaptchaTestForm(forms.Form):
    captcha = CaptchaField()  # 验证码字段
Пример #15
0
class ForgetForm(forms.Form):
    email = forms.EmailField(required=True)
    captcha = CaptchaField(error_messages={'invalid': u'验证码验证错误'})  # 进行验证码的验证
Пример #16
0
class RegisterForm(forms.Form):

    email = forms.EmailField(required=True)
    password = forms.CharField(required=True, min_length=5)
    captcha = CaptchaField(error_messages={"invalid": "The code you enter is invalid!"})
Пример #17
0
class UserLoginForm(forms.Form):
    username = forms.CharField(required=True)
    password = forms.CharField(required=True,
                               min_length=5,
                               error_messages={'invalid': '密码长度太短!'})
    captcha = CaptchaField(error_messages={'invalid': '验证码错误!'})
Пример #18
0
class RegisterForm(forms.Form):
    email = forms.EmailField(required=True)
    password = forms.CharField(min_length=5, required=True, max_length=16)
    captcha = CaptchaField(error_messages={'invalid': '验证码错误'})
Пример #19
0
class ProfileForm(forms.ModelForm):
    captcha =CaptchaField()
    class Meta:
        model = Profile
        fields = ('bio','location',)
Пример #20
0
    def __init__(self, form, user, *args, **kwargs):
        """
        Dynamically add each of the form fields for the given form model 
        instance and its related field model instances.
        """
        self.user = user
        self.form = form
        self.form_fields = form.fields.visible().order_by('position')
        super(FormForForm, self).__init__(*args, **kwargs)

        for field in self.form_fields:
            field_key = "field_%s" % field.id
            if "/" in field.field_type:
                field_class, field_widget = field.field_type.split("/")
            else:
                field_class, field_widget = field.field_type, None

            if field.field_type == 'EmailVerificationField':
                field_class = EmailVerificationField
            else:
                field_class = getattr(forms, field_class)
            field_args = {
                "label": mark_safe(field.label),
                "required": field.required
            }
            arg_names = field_class.__init__.im_func.func_code.co_varnames
            if "max_length" in arg_names:
                field_args["max_length"] = FIELD_MAX_LENGTH
            if "choices" in arg_names:
                choices = field.choices.split(",")
                field_args["choices"] = zip(choices, choices)
            if "initial" in arg_names:
                default = field.default.lower()
                if field_class == "BooleanField":
                    if default == "checked" or default == "true" or \
                        default == "on" or default == "1":
                        default = True
                    else:
                        default = False
                field_args["initial"] = field.default

            if field_widget is not None:
                module, widget = field_widget.rsplit(".", 1)
                field_args["widget"] = getattr(import_module(module), widget)

            self.fields[field_key] = field_class(**field_args)

            self.fields[field_key].widget.attrs['title'] = field.label

        # include pricing options if any
        if (self.form.custom_payment or
                self.form.recurring_payment) and self.form.pricing_set.all():

            currency_symbol = get_setting('site', 'global', 'currencysymbol')

            pricing_options = []
            for pricing in self.form.pricing_set.all():

                if pricing.price == None:
                    pricing_options.append((
                        pricing.pk,
                        mark_safe(
                            '<input type="text" class="custom-price" name="custom_price_%s" value="%s"/> %s'
                            % (pricing.pk,
                               self.data.get('custom_price_%s' % pricing.pk,
                                             unicode()), pricing.label))))
                else:
                    if self.form.recurring_payment:
                        pricing_options.append(
                            (pricing.pk, '%s%s per %s %s - %s' %
                             (currency_symbol, pricing.price,
                              pricing.billing_frequency,
                              pricing.billing_period, pricing.label)))
                    else:
                        pricing_options.append(
                            (pricing.pk, '%s%s %s' %
                             (currency_symbol, pricing.price, pricing.label)))

            self.fields['pricing_option'] = forms.ChoiceField(
                label=_('Pricing'),
                choices=pricing_options,
                widget=forms.RadioSelect)

            self.fields['payment_option'] = forms.ModelChoiceField(
                label=_('Payment Method'),
                empty_label=None,
                queryset=self.form.payment_methods.all(),
                widget=forms.RadioSelect,
                initial=1,
            )

        if not self.user.is_authenticated() and get_setting(
                'site', 'global', 'captcha'):  # add captcha if not logged in
            self.fields['captcha'] = CaptchaField(
                label=_('Type the code below'))
Пример #21
0
class LoginForm(forms.Form):
    username = forms.CharField()
    password = forms.CharField(widget=forms.PasswordInput)
    captcha = CaptchaField(error_messages={'invalid': '验证码错误啊'})
class forgot_pass_form(forms.ModelForm):
    captcha = CaptchaField()

    class Meta:
        model = User
        fields = ['email', 'dateofBirth']
Пример #23
0
class ForgetPasswordForm(forms.Form):
    email = forms.EmailField(required=True)
    captcha = CaptchaField(error_messages={'invalid': '验证码错误'})
Пример #24
0
class UserForm(forms.Form):
    username = forms.CharField(label="用户名", max_length=128, widget=forms.TextInput(attrs={'class': 'form-control'}))
    password = forms.CharField(label="密码", max_length=256, widget=forms.PasswordInput(attrs={'class': 'form-control'}))
    captcha = CaptchaField(label='验证码')
Пример #25
0
class RegisterForm(forms.Form):
    email = forms.CharField(required=True)  # 用户名不能为空
    password = forms.CharField(required=True, min_length=5)  # 密码不能为空,而且最小5位数
    captcha = CaptchaField(error_messages={"invalid": "验证码错误"})
Пример #26
0
class RegisterGetForm(forms.Form):
    captcha = CaptchaField()
Пример #27
0
class ForgetForm(forms.Form):
    email = forms.CharField(required=True)  # 用户名不能为空
    captcha = CaptchaField(error_messages={"invalid": "验证码错误"})
Пример #28
0
class RegisterForm(forms.Form):
    email = forms.EmailField(required=True)
    password = forms.CharField(required=True, min_length=6)
    captcha = CaptchaField(error_messages={"invalid": u"验证码错误"})
Пример #29
0
class ActiveForm(forms.Form):
    # 激活时不需要对邮箱的密码做验证
    # 应用验证码,自定义错误输出key必须与异常一样
    captcha = CaptchaField(error_messages={"invalid": u"验证码错误"})
Пример #30
0
    def clean(self):
        """
        Checks for the identification and password.

        If the combination can't be found will raise an invalid sign in error.

        """
        identification = self.cleaned_data.get('identification')
        password = self.cleaned_data.get('password')

        if identification and password:
            # try to get the user object using only the identification
            try:
                if '@' in identification:
                    auth_user = User.objects.get(email=identification)
                else:
                    auth_user = User.objects.get(username=identification)
            except:
                raise django_forms.ValidationError(_(u"Please enter a correct "
                    "username or email and password. Note that both fields "
                    "are case-sensitive."))

            profile = auth_user.get_profile()
            if isinstance(profile.extra, dict) and\
                    "failed_login_attempts" in profile.extra and\
                    isinstance(profile.extra['failed_login_attempts'], int) and\
                    profile.extra['failed_login_attempts'] >= settings.MAX_ALLOWED_FAILED_LOGIN_ATTEMPTS:
                captcha_field = CaptchaField()
                self.fields.insert(0, 'captcha', captcha_field)
                if 'captcha_0' not in self.data:
                    raise django_forms.ValidationError(_(u"Please, for "
                        u"security reasons validate the captcha"))
                else:
                    value = captcha_field.widget.value_from_datadict(self.data,
                        self.files, self.add_prefix("captcha"))
                    captcha_field.clean(value)
            user = authenticate(identification=identification, password=password)

            if user is None:
                # if user was not authenticated but it does exist, then
                # increment the failed_login_attempts counter
                if not isinstance(profile.extra, dict):
                    profile.extra = dict()

                if 'failed_login_attempts' not in profile.extra or\
                        not isinstance(profile.extra['failed_login_attempts'], int) or\
                        profile.extra['failed_login_attempts'] < 0:
                    profile.extra['failed_login_attempts'] = 1
                else:
                    profile.extra['failed_login_attempts'] += 1
                profile.save()

                # insert captcha in the form if max failed login attempts is
                # reached and we got an invalid login attempt
                if profile.extra['failed_login_attempts'] >= settings.MAX_ALLOWED_FAILED_LOGIN_ATTEMPTS:
                    self.fields.insert(0, 'captcha', CaptchaField())

                raise django_forms.ValidationError(_(u"Please enter a correct "
                    "username or email and password. Note that both fields "
                    "are case-sensitive."))
            else:
                # if the user was authenticated, reset the failed_login_attempts
                # counter
                if not isinstance(profile.extra, dict):
                    profile.extra = dict()
                profile.extra['failed_login_attempts'] = 0
                profile.save()
        return self.cleaned_data
Пример #31
0
class MyRegistrationForm(RegistrationForm):
    """
    Extension of the default registration form to include a captcha
    """

    captcha = CaptchaField(label=_("Are you human?"))