예제 #1
0
class RegistrationForm(forms.Form):
    username = forms.RegexField(
        regex=r'^\w+$',
        widget=forms.TextInput(attrs=dict(required=True, max_length=30)),
        label=_("Username"),
        error_messages={
            'invalid':
            ("This value must contain only letters, numbers and underscores.")
        })
    email = forms.EmailField(
        widget=forms.TextInput(attrs=dict(required=True, max_length=30)),
        label=("Email address"))
    password1 = forms.CharField(widget=forms.PasswordInput(
        attrs=dict(required=True, max_length=30, render_value=False)),
                                label=("Password"))
    password2 = forms.CharField(widget=forms.PasswordInput(
        attrs=dict(required=True, max_length=30, render_value=False)),
                                label=("Password (again)"))

    def clean_username(self):
        try:
            user = User.objects.get(
                username__iexact=self.cleaned_data['username'])
        except User.DoesNotExist:
            return self.cleaned_data['username']
        raise forms.ValidationError(
            _("The username already exists. Please try another one."))

    def clean(self):
        if 'password1' in self.cleaned_data and 'password2' in self.cleaned_data:
            if self.cleaned_data['password1'] != self.cleaned_data['password2']:
                raise forms.ValidationError(
                    _("The two password fields did not match."))
        return self.cleaned_data
예제 #2
0
class RegistrationForm(forms.Form):
    username=forms.CharField(max_length=30,label="username",required=True,error_messages={'invalid':'Username should be unique'})
    email=forms.EmailField(label="emailid",required=True)
    password1=forms.CharField(max_length=30,widget=forms.PasswordInput(),label="password",required=True)
    password2=forms.CharField(max_length=30,widget=forms.PasswordInput(),label="password(again)",required=True)
    ID=forms.CharField(max_length=30,required=True,error_messages={'invalid':'ID should not be Unique and Non Empty'})
    resourceperson=forms.CharField(max_length=30,required=True,error_messages={'invalid':'Resource Person should not be Unique and Non Empty'})
    res_person_workplace=forms.CharField(max_length=30,required=False)
    def clean_username(self):
        u=self.cleaned_data['username']
        try:
            u=User.objects.get(username__exact=u)
        except User.DoesNotExist:
            return self.cleaned_data['username']
        raise forms.ValidationError("Username Already Exists . Please Try another name",code='invalid')
    def clean(self):
        p1=self.cleaned_data['password1']
        p2=self.cleaned_data['password2']
        if p1 is not None and p2 is not None:
            if p1 != p2:
                raise forms.ValidationError("Two passwords did not match")
            else:
                return self.cleaned_data
        else:
            raise forms.ValidationError("Both fields should match")
예제 #3
0
class UserRegistartionForm(forms.ModelForm):
    username = forms.CharField(
        max_length=30,
        widget=forms.TextInput(attrs={'class': 'form-control'}),
        label='Имя пользователя')
    first_name = forms.CharField(
        max_length=30,
        widget=forms.TextInput(attrs={'class': 'form-control'}),
        label='Имя')
    last_name = forms.CharField(
        max_length=40,
        widget=forms.TextInput(attrs={'class': 'form-control'}),
        label='Фамилия')
    email = forms.EmailField(
        max_length=100,
        widget=forms.EmailInput(attrs={'class': 'form-control'}),
        label='Email')
    password = forms.CharField(
        max_length=128,
        strip=False,
        widget=forms.PasswordInput(attrs={'class': 'form-control'}),
        label='Пароль')
    password2 = forms.CharField(
        max_length=128,
        strip=False,
        widget=forms.PasswordInput(attrs={'class': 'form-control'}),
        label='Повторите пароль')
    error_messages = {
        'password_mismatch': _("The two password fields didn't match."),
    }

    class Meta:
        model = AllUsers
        fields = ('username', 'email')
예제 #4
0
class RegistrationForm(forms.Form):
    # username = forms.CharField(label="",widget=forms.TextInput(attrs={'placeholder': 'Nom d\'utilisateur','class':'form-control input-perso'}),max_length=30,min_length=3,validators=[isValidUsername, validators.validate_slug])
    # email = forms.EmailField(label="",widget=forms.EmailInput(attrs={'placeholder': 'Email','class':'form-control input-perso'}),max_length=100,error_messages={'invalid': ("Email invalide.")},validators=[isValidEmail])
    password1 = forms.CharField(
        label="",
        max_length=50,
        min_length=6,
        widget=forms.PasswordInput(attrs={
            'placeholder': 'Mot de passe',
            'class': 'form-control input-perso'
        }))
    password2 = forms.CharField(
        label="",
        max_length=50,
        min_length=6,
        widget=forms.PasswordInput(
            attrs={
                'placeholder': 'Confirmer mot de passe',
                'class': 'form-control input-perso'
            }))

    def clean(self):
        password1 = self.cleaned_data.get('password1')
        password2 = self.cleaned_data.get('password2')

        if password1 and password1 != password2:
            self._errors['password2'] = ErrorList(
                [u"Le mot de passe ne correspond pas."])

        return self.cleaned_data
class Set_new_password(forms.Form):
    password = Password(max_length=50,
                        error_messages=my_default_errors,
                        label='',
                        widget=forms.PasswordInput(
                            attrs={
                                'placeholder': '(رمز عبور (حداقل ۶ کاراکتر',
                                'style': "direction: ltr;",
                                'class': "form-control register-inputs",
                                'type': 'password'
                            }),
                        required=True)
    confirm_password = Password(
        max_length=50,
        error_messages=my_default_errors,
        label='',
        widget=forms.PasswordInput(
            attrs={
                'placeholder': 'تکرار رمز عبور',
                'style': "direction: ltr;",
                'class': "form-control register-inputs",
                'type': 'password'
            }),
        required=True)

    def clean(self):
        cleaned_data = super(Set_new_password, self).clean()
        pw1 = cleaned_data.get("password")
        pw2 = cleaned_data.get("confirm_password")
        if pw1 != pw2:
            raise ValidationError("* رمز عبور و تکرار آن یکسان نمی‌باشد.",
                                  code="password_confirmation_error")
        return cleaned_data
예제 #6
0
class userform(forms.ModelForm):
    username= forms.CharField(widget=forms.TextInput(
        attrs={'class': 'forms-control', 'placeholder': 'Enter username'}
    ), required=True, max_length=50)
    email = forms.CharField(widget=forms.EmailInput(
        attrs={'class': 'forms-control', 'placeholder': 'Enter email ID'}
    ), required=True, max_length=50)
    first_name = forms.CharField(widget=forms.TextInput(
        attrs={'class': 'forms-control', 'placeholder': 'Enter  first name'}
    ), required=True, max_length=50)
    lastname = forms.CharField(widget=forms.TextInput(
        attrs={'class': 'forms-control', 'placeholder': 'Enter last name'}
    ), required=True, max_length=50)
    password = forms.CharField(widget=forms.PasswordInput(
        attrs={'class': 'forms-control', 'placeholder': 'Enter password'}
    ), required=True, max_length=50)
    confirm_password = forms.CharField(widget=forms.PasswordInput(
        attrs={'class': 'forms-control', 'placeholder': 'Enter confirm password'}
    ), required=True, max_length=50)


    class Meta():
        model = User
        fields =['username','email','first_name','last_name','password','confirm_password']

            def clean_username(self):
                user=self.cleaned_data['username']
                try:
                    match = User.objects.get(username = user)
                except:
                    return self.cleaned_data['username'] #user
                raise forms.ValidationError("Username already exist")

            def clean_email(self):
                email = self.cleaned_data['email']
                try:
                    mt = validate_email(email)
                except:
                    return forms.ValidationError("Email is not in correct Format")
                return email


            def clean_confirm_password(self):
                pas = self.cleaned_data['password']
                cpas = self.cleaned_data['confirm_password']
                MIN_LENGTH = 8
                if pas and cpas:
                    if pas != cpas:
                        raise forms.ValidationError("password and confirm password not matched")
                    else:
                        if len(pas) < MIN_LENGTH:
                            raise forms.ValidationError("Password should have atleast %d character" %MIN_LENGTH)
                if pas.isdigit():
                    raise forms.ValidationError("Password should not all numeric")
예제 #7
0
파일: forms.py 프로젝트: Jaimelll/afiliado
class Responsable_Form(forms.Form):
    Numero_Dni = forms.CharField(
        label='Numero de Dni',
        required=True,
        widget=forms.TextInput(attrs={
            'class': 'form-control input-sm',
            'placeholder': 'Numero DNI'
        }))
    Nombre_Responsable = forms.CharField(
        label='Nombres',
        required=True,
        widget=forms.TextInput(attrs={
            'class': 'form-control input-sm',
            'placeholder': 'Nombre Completo'
        }))
    Apellido_Paterno_Responsable = forms.CharField(
        label='Apellido Paterno',
        required=True,
        widget=forms.TextInput(attrs={'class': 'form-control input-sm'}))
    Apellido_Materno_Responsable = forms.CharField(
        label='Apellido Paterno',
        required=True,
        widget=forms.TextInput(attrs={'class': 'form-control input-sm'}))
    Nombre_Usuario = forms.CharField(
        label='Nombre Usuario',
        required=True,
        widget=forms.TextInput(attrs={'class': 'form-control input-sm'}))
    Email = forms.EmailField(
        label='Direccion Email',
        required=True,
        widget=forms.EmailInput(attrs={'class': 'form-control input-sm'}))
    Telefono = forms.CharField(
        label='Numero de telefono',
        required=True,
        widget=forms.TextInput(attrs={'class': 'form-control input-sm'}))
    Region = forms.ChoiceField(label='Region encargada',
                               required=True,
                               widget=forms.Select,
                               choices=choices_regiones)
    contra1 = forms.CharField(
        label='Contraseña',
        required=True,
        widget=forms.PasswordInput(attrs={'class': 'form-control input-sm'}))
    contra2 = forms.CharField(
        label='Confirmar contraseña',
        required=True,
        widget=forms.PasswordInput(attrs={'class': 'form-control input-sm'}))
    clave = forms.CharField(
        label='Clave Unica',
        required=True,
        widget=forms.TextInput(attrs={'class': 'form-control input-sm'}))
예제 #8
0
class UserForm(forms.ModelForm):
    username = forms.CharField(
        widget=forms.TextInput(attrs={'class': 'form-control'}),
        label='ชื่อผู้ใช้ ')
    password = forms.CharField(
        widget=forms.PasswordInput(attrs={'class': 'form-control'}),
        label='รหัสผ่าน ')
    first_name = forms.CharField(
        widget=forms.TextInput(attrs={'class': 'form-control'}),
        label='ชื่อจริง ')
    last_name = forms.CharField(
        widget=forms.TextInput(attrs={'class': 'form-control'}),
        label='นามสกุล ')
    email = forms.EmailField(
        widget=forms.EmailInput(attrs={'class': 'form-control'}),
        label='อีเมล์ ')

    class Meta:
        model = User
        fields = ['username', 'password', 'email', 'first_name', 'last_name']
        help_texts = {
            'username':
            str('Required. 30 characters or fewer. Usernames may contain alphanumeric, _, @, +, . and - characters.<br><br>'
                )
        }
예제 #9
0
class SignUpForm(forms.Form):
    first_name = forms.CharField(
        max_length=15,
        required=True,
        widget=forms.TextInput(attrs={
            'class': 'form-control',
            'placeholder': 'First Name '
        }))
    last_name = forms.CharField(
        max_length=15,
        required=True,
        widget=forms.TextInput(attrs={
            'class': 'form-control',
            'placeholder': 'Last Name '
        }))

    username = forms.CharField(
        max_length=15,
        required=True,
        widget=forms.TextInput(attrs={
            'class': 'form-control',
            'placeholder': 'User Nsme'
        }))

    password = forms.CharField(
        max_length=15,
        required=True,
        widget=forms.PasswordInput(attrs={
            'class': 'form-control',
            'placeholder': 'First Name '
        }))
예제 #10
0
class SignupForm(forms.Form):
    first_name = forms.CharField(
        max_length=40,
        required=True,
        widget=forms.TextInput(attrs={
            'class': 'input',
            'placeholder': 'Enter First Name'
        }))
    last_name = forms.CharField(
        max_length=40,
        required=True,
        widget=forms.TextInput(attrs={
            'class': 'input',
            'placeholder': 'Enter Last Name'
        }))
    username = forms.CharField(
        max_length=40,
        required=True,
        widget=forms.TextInput(attrs={
            'class': 'input',
            'placeholder': 'Enter User Name'
        }))
    password = forms.CharField(
        max_length=40,
        required=True,
        widget=forms.PasswordInput(attrs={
            'class': 'input',
            'placeholder': 'Enter password'
        }))
예제 #11
0
class LoginForm(forms.Form):
    email = forms.EmailField(
        max_length=70,
        error_messages=my_default_errors,
        required=True,
        label='',
        widget=forms.TextInput(
            attrs={
                'placeholder': 'پست الکترونیک',
                'style': "margin-top: 0px; direction: ltr;",
                'class': "form-control register-inputs",
                'type': 'email'
            }))
    password = Password(max_length=50,
                        error_messages=my_default_errors,
                        label='',
                        widget=forms.PasswordInput(
                            attrs={
                                'placeholder': 'رمز عبور',
                                'style': "direction: ltr;",
                                'class': "form-control register-inputs",
                                'type': 'password'
                            }),
                        required=True)
    captcha = CaptchaField(label='',
                           error_messages=captcha_errors,
                           required=True)
예제 #12
0
class PasswordForm(forms.Form):
    client_password = forms.CharField(
        max_length=32,
        widget=forms.PasswordInput(attrs={
            "name": "password",
            "class": "w3-input w3-border"
        }))
예제 #13
0
class CustomerRegisterForm(UserCreationForm):
    email = forms.CharField(label='Email адрес:',
                            widget=forms.EmailInput(
                                attrs={
                                    'class': 'form-control form-control-lg',
                                    'placeholder': 'Введите ваш email'
                                }))

    password1 = forms.CharField(
        label='Пароль:',
        strip=False,
        widget=forms.PasswordInput(
            attrs={
                'class': 'form-control form-control-lg',
                'placeholder': 'Придумайте пароль'
            }))
    password2 = forms.CharField(
        label='Повторите пароль:',
        strip=False,
        widget=forms.PasswordInput(
            attrs={
                'class': 'form-control form-control-lg',
                'placeholder': 'Введите пароль еще раз'
            }))

    class Meta:
        model = User
        fields = ('email', )

    def clean_email(self):
        email = self.cleaned_data.get('email')

        if User.objects.filter(email=email).exists():
            raise forms.ValidationError(
                'Пользователь с таким email уже зарегистрирован')
        return email

    def save(self, commit=True):
        user = super().save(commit=False)
        user.username = self.cleaned_data['email']
        user.set_password(self.cleaned_data["password1"])

        if commit:
            user.save()
        return user
예제 #14
0
파일: forms.py 프로젝트: cz9025/DjangoTest
class RegisterForm(forms.Form):
    gender = (
        ('male', "男"),
        ('female', "女"),
    )
    username = forms.CharField(
        label="用户名",
        max_length=128,
        widget=forms.TextInput(attrs={'class': 'form-control'}))
    password1 = forms.CharField(
        label="密码",
        max_length=256,
        widget=forms.PasswordInput(attrs={'class': 'form-control'}))
    password2 = forms.CharField(
        label="确认密码",
        max_length=256,
        widget=forms.PasswordInput(attrs={'class': 'form-control'}))
    email = forms.EmailField(
        label="邮箱地址", widget=forms.EmailInput(attrs={'class': 'form-control'}))
    sex = forms.ChoiceField(label='性别', choices=gender)
class RegistrationForm(forms.Form):
    username = forms.CharField(
        max_length=30,
        label="username",
        required=True,
        error_messages={'invalid': 'Username should be unique'})
    email = forms.EmailField(label="emailid", required=True)
    password1 = forms.CharField(max_length=30,
                                widget=forms.PasswordInput(),
                                label="password",
                                required=True)
    password2 = forms.CharField(max_length=30,
                                widget=forms.PasswordInput(),
                                label="password(again)",
                                required=True)
    options = [('teacher', 'Teacher'), ('student', 'Student')]
    role = forms.ChoiceField(widget=forms.RadioSelect(),
                             label="Account Type",
                             required=True,
                             choices=options)

    def clean_username(self):
        u = self.cleaned_data['username']
        try:
            u = User.objects.get(username__exact=u)
        except User.DoesNotExist:
            return self.cleaned_data['username']
        raise forms.ValidationError(
            "Username Already Exists . Please Try another name",
            code='invalid')

    def clean(self):
        p1 = self.cleaned_data['password1']
        p2 = self.cleaned_data['password2']
        if p1 is not None and p2 is not None:
            if p1 != p2:
                raise forms.ValidationError("Two passwords did not match")
            else:
                return self.cleaned_data
        else:
            raise forms.ValidationError("Both fields should match")
예제 #16
0
class LoginForm(forms.Form):
    username = forms.CharField(
        max_length=50,
        required=True,
        widget=forms.TextInput(attrs={
            'class': 'input',
            'placeholder': 'Enter Username'
        }))
    password = forms.CharField(
        max_length=50,
        required=True,
        widget=forms.PasswordInput(attrs={
            'class': 'input',
            'placeholder': 'Enter Password'
        }))
예제 #17
0
파일: forms.py 프로젝트: pythongiant/Mesmer
class SignUp(forms.Form):
    """ Sign Up """
    Name = forms.CharField(
        label="Your Name",
        widget=forms.TextInput(attrs={"placeholder": "It's Nice to meet you"}))
    username = forms.CharField(
        max_length=255,
        widget=forms.TextInput(attrs={"placeholder": "Make it Creative"}))
    password = forms.CharField(
        widget=forms.PasswordInput(attrs={"placeholder": "We wont sell it. "}),
        label="Password")
    email = forms.EmailField(label="Email Id")
    DateOfBirth = forms.DateField(label="Date of Birth")

    Bio = forms.CharField(widget=forms.Textarea(
        attrs={"placeholder": "Tell us about yourself"}))
    profilePic = forms.FileField()
예제 #18
0
class UserLoginForm(ModelForm):
    class Meta:
        model = User
        fields = ["username", "password"]

    username = forms.CharField(
        label="Username",
        widget=forms.TextInput(attrs={
            "placeholder": "jbsmooth",
            "class": "form-control"
        }),
        required=True,
    )
    password = forms.CharField(
        label="Password",
        widget=forms.PasswordInput(attrs={
            "placeholder": "shhhhh..",
            "class": "form-control"
        }),
    )
예제 #19
0
class UserRegistrationForm(forms.Form):
    first_name = forms.CharField(
        label="First Name",
        required=False,
        widget=forms.TextInput(attrs={"class": "form-control"}),
    )
    last_name = forms.CharField(
        label="Last Name",
        required=False,
        widget=forms.TextInput(attrs={"class": "form-control"}),
    )
    username = forms.CharField(
        label="Username",
        required=True,
        widget=forms.TextInput(attrs={"class": "form-control"}),
    )
    password = forms.CharField(widget=forms.PasswordInput(
        attrs={"class": "form-control"}))
    birth_date = forms.DateField(
        widget=forms.DateInput(attrs={"class": "form-control"}),
        required=False)
    profile_pic = forms.ImageField(required=False)
예제 #20
0
class CustomerLoginForm(forms.Form):
    email = forms.CharField(widget=forms.EmailInput(
        attrs={
            'class': 'form-control',
            'placeholder': 'Email адрес'
        }))

    password = forms.CharField(widget=forms.PasswordInput(
        attrs={
            'class': 'form-control',
            'placeholder': 'Пароль'
        }))

    def clean(self):
        email = self.cleaned_data.get('email')
        password = self.cleaned_data.get('password')

        if email and password:
            customer = User.objects.filter(email=email).first()

            if not customer:
                raise forms.ValidationError(
                    'Покупатель с таким адресом email не зарегистрирован')

            else:
                username = customer.username

                user = authenticate(
                    username=username,
                    password=password,
                )

                if not user:
                    raise forms.ValidationError(
                        'Неверный адрес email или пароль')

        return super().clean()
예제 #21
0
class LoginForm(forms.Form):
    username = forms.CharField(label='CNE', max_length=14)
    password = forms.CharField(widget=forms.PasswordInput())
예제 #22
0
class LoginForm(forms.Form):
    login = forms.CharField(label='Username', max_length=64)
    password = forms.CharField(label='Password',
                               max_length=100,
                               widget=forms.PasswordInput())
예제 #23
0
class RegistrationForm(forms.Form):
    email = forms.EmailField(
        max_length=70,
        error_messages=my_default_errors,
        required=True,
        label='',
        widget=forms.TextInput(
            attrs={
                'placeholder': 'پست الکترونیک',
                'style': "margin-top: 0px; direction: ltr;",
                'class': "form-control register-inputs",
                'type': 'email'
            }))
    password = Password(
        max_length=50,
        error_messages=my_default_errors,
        label='',
        widget=forms.PasswordInput(
            attrs={
                'placeholder': '(رمز عبور (حداقل ۶ کاراکتر',
                'style': "direction: ltr;",
                'class': "form-control register-inputs",
                'type': 'password'
            }),
        required=True,
    )
    confirm_password = Password(
        max_length=50,
        error_messages=my_default_errors,
        label='',
        widget=forms.PasswordInput(
            attrs={
                'placeholder': ' تکرار رمز عبور',
                'style': "direction: ltr;",
                'class': "form-control register-inputs",
                'type': 'password'
            }),
        required=True)
    first_name = forms.CharField(
        max_length=100,
        error_messages=my_default_errors,
        label='',
        required=True,
        widget=forms.TextInput(
            attrs={
                'placeholder': 'نام (فارسی)',
                'style': "direction: rtl;",
                'class': "form-control register-inputs"
            }))
    last_name = forms.CharField(max_length=100,
                                error_messages=my_default_errors,
                                label='',
                                required=True,
                                widget=forms.TextInput(
                                    attrs={
                                        'placeholder': 'نام خانوادگی (فارسی)',
                                        'style': "direction: rtl;",
                                        'class': "form-control register-inputs"
                                    }))
    mobile_number = Mobile_Number(
        max_length=100,
        error_messages=my_default_errors,
        label='',
        required=True,
        widget=forms.TextInput(
            attrs={
                'placeholder': 'تلفن همراه (۱۱ رقم وارد کنید.)',
                'style': "direction: lrt;",
                'class': "form-control register-inputs"
            }))
    last_educational_level = forms.ChoiceField(
        error_messages=my_default_errors,
        label='',
        widget=forms.Select(
            attrs={
                'class': "form-control register-inputs",
                'style': "text-align-last:center;"
            }),
        choices=educational_level_types,
        required=True,
    )
    last_educational_University = forms.CharField(
        error_messages=my_default_errors,
        max_length=500,
        label='',
        widget=forms.TextInput(
            attrs={
                'placeholder': 'آخرین دانشگاه محل تحصیل (فارسی)',
                'style': "direction: rtl;",
                'class': "form-control register-inputs"
            }))
    day = forms.CharField(
        required=False,
        max_length=2,
        label='تاریخ تولد:',
        error_messages='',
        widget=forms.TextInput(
            attrs={
                'placeholder': ' روز',
                'style':
                "direction: ltr; width:60px; text-align-last:center; display:inline;",
                'class': "form-control register-inputs"
            }))
    month = forms.CharField(
        required=False,
        max_length=2,
        label='',
        error_messages='',
        widget=forms.TextInput(
            attrs={
                'placeholder': ' ماه',
                'style':
                "direction: ltr; width:60px; text-align-last:center; display:inline;",
                'class': "form-control register-inputs"
            }))
    year = forms.CharField(
        required=False,
        max_length=4,
        label='',
        error_messages='',
        widget=forms.TextInput(
            attrs={
                'placeholder': ' (سال(چهار رقم',
                'style':
                "direction: ltr; width:60px; text-align-last:center; display:inline;",
                'class': "form-control register-inputs"
            }))
    city = forms.ChoiceField(
        label='',
        widget=forms.Select(
            attrs={
                'class': "form-control register-inputs",
                'style': "text-align-last:center;"
            }),
        choices=city_types,
        required=True,
    )
    captcha = CaptchaField(label='',
                           required=True,
                           error_messages=captcha_errors)
    sending_daily_email = forms.BooleanField(
        required=False,
        label='',
        widget=forms.CheckboxInput(
            attrs={
                'class':
                "form-control register-inputs",
                'style':
                " position: relative;right: 26px !important; top: 14px !important;"
            }))

    def clean(self):
        cleaned_data = super(RegistrationForm, self).clean()
        pw1 = cleaned_data.get("password")
        pw2 = cleaned_data.get("confirm_password")
        new_email = cleaned_data.get('email')
        previous_user = User.objects.filter(username=new_email)
        city = cleaned_data.get('city')
        year = cleaned_data.get('year')
        month = cleaned_data.get('month')
        day = cleaned_data.get('day')

        if previous_user.__len__() != 0:
            print(type(previous_user))
            raise ValidationError(
                "* کاربر با ایمیل داده شده در سامانه موجود است.",
                code="password_confirmation_error")
        if pw1 != pw2:
            raise ValidationError("* رمز عبور و تکرار آن یکسان نمی‌باشد.",
                                  code="password_confirmation_error")
        if (str(year).__len__() != 4 or year == '' or int(year) < 1310):
            raise ValidationError(
                "* لطفا سال را چهار رقمی  و معتبر وارد کنید.",
                code="password_confirmation_error")
        if str(month).__len__() > 2 or int(month) > 12 or int(month) < 1:
            raise ValidationError(
                "* لطفا ماه را حداکثر دو رقمی  و کمتر از ۱۲ وارد کنید.",
                code="password_confirmation_error")
        if str(day).__len__() > 2 or int(day) > 31 or int(day) < 1:
            raise ValidationError(
                "* لطفا روز را حداکثر دو رقمی  و کمتر از ۳۲ وارد کنید.",
                code="password_confirmation_error")
        return cleaned_data
예제 #24
0
파일: forms.py 프로젝트: pythongiant/Mesmer
class LoginForm(forms.Form):
    username = forms.CharField(max_length=255, widget=forms.TextInput())
    password = forms.CharField(widget=forms.PasswordInput(), label="Password")
예제 #25
0
class UserForm(forms.ModelForm):
    password = forms.CharField(widget=forms.PasswordInput())

    class Meta:
        model = User
        fields = ('username', 'email', 'password')
예제 #26
0
class Authenticate(forms.Form):
    Username = forms.CharField(label="Username:"******" ")
    Password = forms.CharField(widget=forms.PasswordInput(), initial="")
예제 #27
0
class LoginForm(forms.Form):
    username = forms.CharField(
        required=True, widget=forms.TextInput(attrs={'placeholder': 'Login'}))
    password = forms.CharField(
        required=True,
        widget=forms.PasswordInput(attrs={'placeholder': 'Password'}))
예제 #28
0
class CustomUserAuthenticationForm(forms.Form):
    """
    Base class for authenticating users. Extend this to get a form that accepts
    email/password logins.
    """
    email = forms.EmailField(widget=forms.TextInput(attrs={'autofocus': True}))
    password = forms.CharField(
        label=_("Password"),
        strip=False,
        widget=forms.PasswordInput(attrs={'autocomplete': 'current-password'}),
    )

    error_messages = {
        'invalid_login':
        _("Please enter a correct %(email)s and password. Note that both "
          "fields may be case-sensitive."),
        'inactive':
        _("This account is inactive."),
    }

    def __init__(self, request=None, *args, **kwargs):
        """
        The 'request' parameter is set for custom auth use by subclasses.
        The form data comes in via the standard 'data' kwarg.
        """
        self.request = request
        self.user_cache = None
        super().__init__(*args, **kwargs)

        # Set the max length and label for the "email" field.
        self.email_field = CustomUser._meta.get_field(CustomUser.EMAIL_FIELD)
        email_max_length = self.email_field.max_length or 254
        self.fields['email'].max_length = email_max_length
        self.fields['email'].widget.attrs['maxlength'] = email_max_length
        if self.fields['email'].label is None:
            self.fields['email'].label = capfirst(
                self.email_field.verbose_name)

    def clean(self):
        email = self.cleaned_data.get('email')
        password = self.cleaned_data.get('password')

        if email is not None and password:
            self.user_cache = authenticate(self.request,
                                           email=email,
                                           password=password)
            if self.user_cache is None:
                raise self.get_invalid_login_error()
            else:
                self.confirm_login_allowed(self.user_cache)

        return self.cleaned_data

    def confirm_login_allowed(self, user):
        """
        Controls whether the given User may log in. This is a policy setting,
        independent of end-user authentication. This default behavior is to
        allow login by active users, and reject login by inactive users.

        If the given user cannot log in, this method should raise a
        ``forms.ValidationError``.

        If the given user may log in, this method should return None.
        """
        if not user.is_active:
            raise forms.ValidationError(
                self.error_messages['inactive'],
                code='inactive',
            )

    def get_user(self):
        return self.user_cache

    def get_invalid_login_error(self):
        return forms.ValidationError(
            self.error_messages['invalid_login'],
            code='invalid_login',
            params={'email': self.email_field.verbose_name},
        )
예제 #29
0
class CreatePassForm(ModelForm):
    password = forms.CharField(label='Password', widget=forms.PasswordInput())

    class Meta:
        model = PasswordAccount
        fields = ['title', 'username', 'password', 'url', 'additional_notes']