class Meta(UserCreationForm): model = User email = forms.EmailField() fields = ('email', 'first_name', 'last_name') widgets = { 'first_name': forms.TextInput(attrs={ 'class': 'form-control', 'required': 'required' }), 'last_name': forms.TextInput(attrs={ 'class': 'form-control', 'required': 'required' }), 'email': forms.EmailInput(attrs={ 'class': 'form-control', 'required': 'required' }), 'password1': forms.PasswordInput(attrs={'class': 'form-control'}), 'password2': forms.PasswordInput(attrs={'class': 'form-control'}), }
class UserChangePassword(PasswordChangeForm): old_password = forms.CharField(label="Contraseña actual", widget=forms.PasswordInput()) new_password1 = forms.CharField(label="Contraseña nueva", widget=forms.PasswordInput()) new_password2 = forms.CharField(label="Confirmar nueva contraseña", widget=forms.PasswordInput()) # verificacion contaseña actual coincide def clean_old_password(self): try: return super(UserChangePassword, self).clean_old_password() except: raise forms.ValidationError("Contraseña actual incorrecta") # vericifacion contraseña nueva cumple con los parametros de seguridad def clean_new_password2(self): password1 = self.cleaned_data['new_password1'] password2 = self.cleaned_data['new_password2'] if password1 and password2: if password1 != password2: raise forms.ValidationError('Contraseñas no coinciden') try: password_validation.validate_password(password2, self.user) except password_validation.ValidationError as errores: mensajes = [] for m in errores.messages: if m == 'This password is too short. It must contain at least 8 characters.': mensajes.append('Contraseña muy corta, debe contener más de 7 caracteres') if m == 'This password is too common.': mensajes.append('Contraseña muy común') if m == 'This password is entirely numeric.': mensajes.append('Contraseña no puede contener solo números') if m.startswith("The password is too similar"): mensajes.append('Contraseña muy similar a los datos del usuario') raise forms.ValidationError(mensajes) return password2
class UserForm(ModelForm): username = forms.CharField(max_length=50) first_name = forms.CharField(max_length=20) last_name = forms.CharField(max_length=20) email = forms.EmailField() password = forms.CharField(widget=forms.PasswordInput()) password2 = forms.CharField(widget=forms.PasswordInput()) class Meta: model = Usuario fields = ('picture', 'country', 'city') def clean_username(self): """Comprueba que no exista un username igual en la Base de Datos""" username = self.cleaned_data['username'] if User.objects.filter(username=username): raise forms.ValidationError('Nombre de usuario ya registrado.') return username def clean_email(self): """Comprueba que no exista un email igual en la Base de Datos""" email = self.cleaned_data['email'] if User.objects.filter(email=email): raise forms.ValidationError('Ya existe un email igual registado.') return email def clean_password2(self): """Comprueba que password y password2 segan iguales""" password = self.cleaned_data['password'] password2 = self.cleaned_data['password2'] if password != password2: raise forms.ValidationError('Las Claves no coinciden.') return password2
def __init__(self, *args, **kwargs): super(SignUpForm, self).__init__(*args, **kwargs) self.fields['username'].widget = forms.TextInput( attrs={ 'class': 'utf-with-border', 'placeholder': 'Username' }) self.fields['email'].widget = forms.EmailInput(attrs={ 'class': 'utf-with-border', 'placeholder': 'Email' }) self.fields['password1'].widget = forms.PasswordInput( attrs={ 'class': 'utf-with-border', 'name': 'password1', 'placeholder': 'Password' }) self.fields['password2'].widget = forms.PasswordInput( attrs={ 'class': 'utf-with-border', 'name': 'password2', 'placeholder': 'Repeat Password' })
class NewPasswordForm(forms.ModelForm): password = forms.CharField( min_length=8, widget=forms.PasswordInput(attrs={'placeholder': 'Password'}), help_text=[ "Your Password can't be too similar to your other personal information.", "Your Password must contain at least 8 characters." "Your Password can't be a commonly used password.", "Your Password can't be entirely numeric." ]) password1 = forms.CharField( min_length=8, widget=forms.PasswordInput(attrs={'placeholder': 'Confirm Password'}), help_text="Enter the same password as before,for validtion.") errors_messages = { 'password_mismatch': "The two password fields didn’t match.", } class Meta: model = User fields = ['password'] def clean(self, *args, **kwargs): password = self.cleaned_data.get('password') password1 = self.cleaned_data.get('password1') if password and password1 and password != password1: raise forms.ValidationError( self.errors_messages['password_mismatch'], code='password_mismatch') return super(NewPasswordForm, self).clean(*args, **kwargs)
class CustomUserCreateForm(forms.ModelForm): password1 = forms.CharField(label='登录密码', widget=forms.PasswordInput()) password2 = forms.CharField(label='重复密码', widget=forms.PasswordInput()) class Meta: model = CustomUsers fields = [ 'email', 'username', ] def clean_password2(self): password1 = self.cleaned_data.get("password1") password2 = self.cleaned_data.get("password2") print('p1', password1, 'p2', password2) if password1 and password2 and password1 != password2: raise ValidationError( self.error_messages['password_mismatch'], code='password_mismatch', ) return password2 def save(self, commit=True): # Save the provided password in hashed format user = super().save(commit=False) user.set_password(self.cleaned_data["password1"]) if commit: user.save() return user
class UserForm(ModelForm): username = forms.CharField(label="Usuario", max_length=20) first_name = forms.CharField(label="Nombres", max_length=20) last_name = forms.CharField(label="Apellidos", max_length=20) foto = forms.FileField(required=False) email = forms.EmailField(label="Correo electrónico") password = forms.CharField(label="Contraseña", widget=forms.PasswordInput()) password2 = forms.CharField(label="Confirmación Contraseña", widget=forms.PasswordInput()) ADMINISTRADOR = 1 USER_GTI = 2 ROLE_CHOICES = ( (USER_GTI, 'Miembro GTI'), (ADMINISTRADOR, 'Administrador'), ) roles = forms.ChoiceField(choices=ROLE_CHOICES) class Meta: model = User fields = ['username', 'first_name', 'last_name', 'email', 'password', 'password2', 'roles', 'foto'] # Verificacion usuario unico def clean_username(self): username = self.cleaned_data['username'] if User.objects.filter(username=username): raise forms.ValidationError('Nombre de usuario ya ha sido tomado') return username # verificacion correo unico def clean_email(self): email = self.cleaned_data['email'] if User.objects.filter(email=email): raise forms.ValidationError('Correo ya ha sido registrado') return email # verificacion las contraseñas coinciden y seguridad def clean_password2(self): password = self.cleaned_data['password'] password2 = self.cleaned_data['password2'] if password != password2: raise forms.ValidationError('Contraseñas no coinciden') try: password_validation.validate_password(password2) except password_validation.ValidationError as errores: mensajes = [] for m in errores.messages: if m == 'This password is too short. It must contain at least 8 characters.': mensajes.append('Contraseña muy corta, debe contener más de 7 caracteres') if m == 'This password is too common.': mensajes.append('Contraseña muy común') if m == 'This password is entirely numeric.': mensajes.append('Contraseña no puede contener solo números') if m.startswith("The password is too similar"): mensajes.append('Contraseña muy similar a los datos del usuario') raise forms.ValidationError(mensajes) return password2
class UserForm(ModelForm): username = forms.CharField(label="Usuario", max_length=50) first_name = forms.CharField(label="Nombres", max_length=50) last_name = forms.CharField(label="Apellidos", max_length=50) email = forms.EmailField(label="Correo electrónico", widget=forms.EmailInput()) password = forms.CharField(label="Contraseña", widget=forms.PasswordInput()) password2 = forms.CharField(label="Confirmación de contraseña", widget=forms.PasswordInput()) class Meta: model = User fields = [ 'username', 'first_name', 'last_name', 'email', 'password', 'password2' ] # verificacion correo unico def clean_username(self): username = self.cleaned_data['username'] if User.objects.filter(username=username): raise forms.ValidationError('Correo ya ha sido registrado') return username # verificacion las contraseñas coinciden y seguridad def clean_password2(self): password = self.cleaned_data['password'] password2 = self.cleaned_data['password2'] if password != password2: raise forms.ValidationError('Contraseñas no coinciden') try: password_validation.validate_password(password2) except password_validation.ValidationError as errores: mensajes = [] for m in errores.messages: if m == 'This password is too short. It must contain at least 8 characters.': mensajes.append( 'Contraseña muy corta, debe contener más de 7 caracteres' ) if m == 'This password is too common.': mensajes.append('Contraseña muy común') if m == 'This password is entirely numeric.': mensajes.append( 'Contraseña no puede contener solo números') if m.startswith("The password is too similar"): mensajes.append( 'Contraseña muy similar a los datos del usuario') raise forms.ValidationError(mensajes) return password2
class TrabajadorForm(ModelForm): nombre = forms.CharField(max_length=50) apellidos = forms.CharField(max_length=50) correo = forms.CharField(max_length=50) usuario = forms.CharField(max_length=50) contrasenia = forms.CharField(widget=forms.PasswordInput()) contrasenia2 = forms.CharField(widget=forms.PasswordInput()) class Meta: model = User fields = [ 'nombre', 'apellidos', 'correo', 'usuario', 'contrasenia', 'contrasenia2' ]
class UserLoginForm(forms.Form): username = UsernameField(label='Username',widget=forms.TextInput(attrs={'autofocus': True ,'placeholder': 'Username'})) password = forms.CharField( label="Password", strip=False, widget=forms.PasswordInput(attrs={'autocomplete': 'current-password' , 'placeholder':'Password'}), ) error_message = { 'username': _('The %(username)s doesn\'t Exists Please Register to come in our members ^_^'), 'password': '******', } def clean(self, *args , **kwargs): username = self.cleaned_data.get("username") password = self.cleaned_data.get('password') try: user = User.objects.get(username=username) if not user.is_active: raise forms.ValidationError("This Account isn't Active please Activate your account to login") except User.DoesNotExist: raise forms.ValidationError(self.error_message['username'] , params={'username': username}) if not user.check_password(password): raise forms.ValidationError(self.error_message['password'] , code=self.error_message['password']) return super(UserLoginForm, self).clean(*args , **kwargs)
class FormLogin(forms.Form): email_login = forms.CharField( widget=forms.EmailInput(attrs={'class': 'form-control'}), label='Usuario') password_login = forms.CharField( widget=forms.PasswordInput(attrs={'class': 'form-control'}), label='Contraseña')
class LoginForm(forms.Form): login = forms.CharField( required=True, max_length=64, widget=forms.TextInput(attrs={'id': 'input_feild_email-id'})) password = forms.CharField(required=True, max_length=64, widget=forms.PasswordInput()) class Meta: error_messages = { 'login': { 'user_not_found': "Пользователя не существует" }, 'password': { 'password_mismatch': "Не верный пароль", }, } def clean_login(self): login = self.cleaned_data.get('login') if not User.objects.filter(username=login).exists(): raise ValidationError( self.Meta.error_messages['login']['user_not_found'], code='user_not_found', ) return login
class UserForm(forms.Form): username = forms.CharField( widget=forms.TextInput(attrs={ 'class': 'form-control', 'placeholder': 'Enter Your Username' }), required=True, max_length=60) email = forms.CharField( widget=forms.EmailInput(attrs={ 'class': 'form-control', 'placeholder': 'Enter Your Email' }), required=True, max_length=60) first_name = forms.CharField( widget=forms.TextInput(attrs={ 'class': 'form-control', 'placeholder': 'Enter Your First Name' }), required=True, max_length=60) last_name = forms.CharField( widget=forms.TextInput(attrs={ 'class': 'form-control', 'placeholder': 'Enter Your Last Name' }), required=True, max_length=60) password = forms.CharField( widget=forms.PasswordInput(attrs={ 'class': 'form-control', 'placeholder': 'Enter Your Password' }), required=True, max_length=60) confirm_password = forms.CharField( widget=forms.PasswordInput(attrs={ 'class': 'form-control', 'placeholder': 'Confirm Password' }), required=True, max_length=60) class Meta: model = User fields = ['username', 'email', 'first_name', 'last_name', 'password']
class SignUpForm(forms.ModelForm): password1 = forms.CharField(max_length=100, widget=forms.PasswordInput()) password2 = forms.CharField(max_length=100, widget=forms.PasswordInput()) # def __init__(self, *args, **kwargs): # super(SignUpForm, self).__init__(*args, **kwargs) # self.fields['username'].widget = forms.TextInput(attrs="{}") class Meta: model = CustomUser fields = ['username', 'password1', 'password2'] # def signup(self, request, user, *args, **kwargs): # user.password1 = user.cleaned_data['password1'] # user.password2 = user.cleaned_data['password2'] # user.save() # return user
class loginForm(ModelForm): usernameL = forms.CharField(label="Usuario", max_length=50) passwordL = forms.CharField(label="Contraseña", widget=forms.PasswordInput()) class Meta: model = User fields = ['usernameL', 'passwordL']
class ClientForm(ModelForm): nombre = forms.CharField( max_length=User._meta.get_field('first_name').max_length, label='Nombres') apellido = forms.CharField( max_length=User._meta.get_field('last_name').max_length, label='Apellidos') departamento = forms.ChoiceField( choices=Cliente._meta.get_field('departamento').choices, label='Departamento') ciudad = forms.ChoiceField( choices=Cliente._meta.get_field('ciudad').choices, label='Ciudad') numero_identificacion = forms.CharField(max_length=20) tipo_identificacion = forms.ChoiceField( choices=Cliente._meta.get_field('tipo_identificacion').choices) telefono_contacto = forms.CharField(max_length=15, label='Telefono de Contacto') correo = forms.EmailField(max_length=50, label='Correo electrónico') direccion = forms.CharField(max_length=150, label='Direcció de Residencia') contrasena = forms.CharField(widget=forms.PasswordInput(), label='Contraseña') contrasena2 = forms.CharField(widget=forms.PasswordInput(), label='Confirma tu contraseña') class Meta: model = User fields = [ 'nombre', 'apellido', 'departamento', 'ciudad', 'numero_identificacion', 'tipo_identificacion', 'telefono_contacto', 'correo', 'direccion', 'contrasena', 'contrasena2' ] def clean_contrasena2(self): password = self.cleaned_data['contrasena'] password2 = self.cleaned_data['contrasena2'] if password != password2: raise forms.ValidationError('Las claves no coinciden.') return password2 def clean_correo(self): email = self.cleaned_data['correo'] if User.objects.filter(email=email): raise forms.ValidationError('Ya existe un email igual registrado.') return email
class loginForm(ModelForm): usernameL = forms.EmailField(label="Correo electrónico", widget=forms.EmailInput()) passwordL = forms.CharField(label="Contraseña", widget=forms.PasswordInput()) class Meta: model = User fields = ['usernameL', 'passwordL']
class FormSignup(Form): first_name = forms.CharField(max_length=20) last_name = forms.CharField(max_length=20) username = forms.EmailField( max_length=254, help_text='Email', required=True, error_messages={'required': 'Ingrese una dirección de correo válida'}) password = forms.CharField(widget=forms.PasswordInput()) password2 = forms.CharField(widget=forms.PasswordInput()) mobile = forms.CharField(max_length=10, required=True) document = forms.CharField(max_length=20, required=True) def clean_username(self): username = self.cleaned_data['username'] if User.objects.filter(username=username): raise forms.ValidationError('Este usuario ya existe') return username def clean_password2(self): password = self.cleaned_data['password'] password2 = self.cleaned_data['password2'] if password != password2: raise forms.ValidationError('Contraseñas no coinciden') try: password_validation.validate_password(password2) except password_validation.ValidationError as errores: mensajes = [] for m in errores.messages: if m == 'This password is too short. It must contain at least 8 characters.': mensajes.append( 'Contraseña muy corta, debe contener más de 7 caracteres' ) if m == 'This password is too common.': mensajes.append('Contraseña muy común') if m == 'This password is entirely numeric.': mensajes.append( 'Contraseña no puede contener solo números') if m.startswith("The password is too similar"): mensajes.append( 'Contraseña muy similar a los datos del usuario') raise forms.ValidationError(mensajes) return password2
class LoginForm(forms.Form): username = forms.CharField(max_length=100) password = forms.CharField(widget=forms.PasswordInput(render_value=False), max_length=100) def login(self, request): username = request.POST['username'] password = request.POST['password'] user = authenticate(request, username=username, password=password) return user
class CreateConnectorForm(forms.ModelForm): conn_name = forms.CharField(label=ugettext('Connection name'), widget=forms.TextInput(attrs={ 'class': 'form-control', 'placeholder': ugettext('Connection name'), })) db_type = forms.ChoiceField(label=ugettext('Type'), choices=Connector.DB_TYPES, widget=forms.Select(attrs={ 'class': 'form-control', })) host = forms.CharField(label=ugettext('Host'), widget=forms.TextInput(attrs={ 'class': 'form-control', 'placeholder': ugettext('Host'), })) port = forms.IntegerField(label=ugettext('Port'), widget=forms.NumberInput(attrs={ 'class': 'form-control', 'placeholder': ugettext('Port'), })) username = forms.CharField(label=ugettext('Username'), required=False, widget=forms.TextInput(attrs={ 'class': 'form-control', 'placeholder': ugettext('Username'), })) password = forms.CharField(label=ugettext('Password'), required=False, widget=forms.PasswordInput(attrs={ 'class': 'form-control', 'placeholder': ugettext('Password'), })) db_instance = forms.CharField(label=ugettext('Database'), widget=forms.TextInput(attrs={ 'class': 'form-control', 'placeholder': ugettext('Database'), })) def clean(self): cleaned_data = super().clean() try: create_connection(cleaned_data.get('db_type'), cleaned_data.get('username'), cleaned_data.get('password'), cleaned_data.get('host'), cleaned_data.get('port'), cleaned_data.get('db_instance')) except: raise forms.ValidationError( ugettext('Can not connect to database with settings, please recheck settings again.'), code='invalid' ) class Meta: model = Connector fields = [ 'conn_name', 'db_type', 'host', 'port', 'username', 'password', 'db_instance', ]
class SignUpForm(forms.ModelForm): password1 = forms.CharField(max_length=200, widget=forms.PasswordInput()) password2 = forms.CharField(max_length=200, widget=forms.PasswordInput()) # called this to override init constructor because i wanted to style the password field and other fields def __init__(self, *args, **kwargs): super(SignUpForm, self).__init__(*args, **kwargs) self.fields['username'].widget = forms.TextInput( attrs={ 'class': 'utf-with-border', 'placeholder': 'Username' }) self.fields['email'].widget = forms.EmailInput(attrs={ 'class': 'utf-with-border', 'placeholder': 'Email' }) self.fields['password1'].widget = forms.PasswordInput( attrs={ 'class': 'utf-with-border', 'name': 'password1', 'placeholder': 'Password' }) self.fields['password2'].widget = forms.PasswordInput( attrs={ 'class': 'utf-with-border', 'name': 'password2', 'placeholder': 'Repeat Password' }) class Meta: model = CustomUser fields = ['username', 'email', 'password1', 'password2'] def signup(self, request, user, *args, **kwargs): user.password1 = self.cleaned_data['password1'] user.password2 = self.cleaned_data['password2'] user.save() return user
class AddressForm(forms.Form): email = forms.CharField(widget=forms.TextInput( attrs={'placeholder': 'Email'})) password = forms.CharField(widget=forms.PasswordInput()) address_1 = forms.CharField( label='Address1', widget=forms.TextInput(attrs={'placeholder': '1234 Main St'})) address_2 = forms.CharField(widget=forms.TextInput( attrs={'placeholder': 'Apartment, studio, or floor'})) city = forms.CharField() state = forms.ChoiceField(choices=STATES) zip_code = forms.CharField(label='Zip') check_me_out = forms.BooleanField(required=False)
class UserForm(ModelForm): username = forms.CharField( widget=forms.TextInput(attrs={'class': 'form-control'}), label='Usuario' ) password = forms.CharField( widget=forms.PasswordInput(attrs={'class': 'form-control'}), label='Contrase?a' ) # Create your models here. class Meta: model = User fields = ['username', 'password']
class UserRegisterForm(forms.ModelForm): YEARS = [i for i in range(1935, 2005)] username = forms.CharField(max_length=128) password = forms.CharField(widget=forms.PasswordInput()) first_name = forms.CharField(max_length=128) last_name = forms.CharField(max_length=128) email = forms.EmailField(max_length=250) date_of_birth = forms.DateField(widget=forms.SelectDateWidget(years=YEARS)) class Meta: model = User fields = [ 'username', 'password', 'first_name', 'last_name', 'email', 'date_of_birth', ]
class AuthenticationFormB(AuthenticationForm): username = forms.CharField(max_length=254, widget=forms.TextInput(attrs={'class': 'form-control form-control-lg'})) password = forms.CharField(label="Password", widget=forms.PasswordInput(attrs={'class': 'form-control form-control-lg'}))
class RegisterForm(forms.ModelForm): """ A form that creates a user, with no privileges, from the given username and password. """ error_messages = { 'password_mismatch': '两个密码字段不匹配!', } username = forms.CharField( required=True, label="用户名", widget=forms.TextInput(attrs={ 'class': 'form-control', 'autofocus': '' }), ) password1 = forms.CharField( required=True, label="密码", strip=False, widget=forms.PasswordInput(attrs={ 'class': 'form-control', 'autocomplete': 'new-password' }), ) password2 = forms.CharField( required=True, label="确认密码", widget=forms.PasswordInput(attrs={ 'class': 'form-control', 'autocomplete': 'new-password' }), strip=False, ) captcha = CaptchaField(required=True, error_messages={'invalid': "验证码错误"}) class Meta: model = UserProfile fields = ("username", ) field_classes = {'username': UsernameField} def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if self._meta.model.USERNAME_FIELD in self.fields: self.fields[self._meta.model. USERNAME_FIELD].widget.attrs['autofocus'] = True def clean_password2(self): password1 = self.cleaned_data.get("password1") password2 = self.cleaned_data.get("password2") if password1 and password2 and password1 != password2: raise forms.ValidationError( self.error_messages['password_mismatch'], code='password_mismatch', ) return password2 def _post_clean(self): super()._post_clean() # Validate the password after self.instance is updated with form data # by super(). password = self.cleaned_data.get('password2') if password: try: password_validation.validate_password(password, self.instance) except forms.ValidationError as error: self.add_error('password2', error) def save(self, commit=True): user = super().save(commit=False) user.set_password(self.cleaned_data["password1"]) if commit: user.save() return user
class LoginForm(forms.Form): """ Base class for authenticating users. Extend this to get a form that accepts username/password login. """ username = forms.CharField(widget=forms.TextInput(attrs={ 'class': 'form-control', 'autofocus': True, })) password = forms.CharField( label="Password", strip=False, widget=forms.PasswordInput(attrs={ 'class': 'form-control', 'autocomplete': 'current-password' }), ) error_messages = { 'invalid_login': ("请输入正确的用户名和密码。" "字段可能区分大小写。"), '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 "username" field. self.username_field = UserProfile._meta.get_field( UserProfile.USERNAME_FIELD) username_max_length = self.username_field.max_length or 254 self.fields['username'].max_length = username_max_length self.fields['username'].widget.attrs['maxlength'] = username_max_length def clean(self): username = self.cleaned_data.get('username') password = self.cleaned_data.get('password') if username is not None and password: self.user_cache = authenticate(self.request, username=username, 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={'username': self.username_field.verbose_name}, )
class UserForm(forms.ModelForm): password = forms.CharField(widget=forms.PasswordInput()) class Meta: model = User fields = ('username', 'email', 'password')
class UserRegisterForm(forms.ModelForm): first_name = forms.CharField( label="First Name", max_length=30, min_length=4, widget=forms.TextInput(attrs={ 'autofocus': True, 'placeholder': 'First Name' }), help_text='should enter at least 4 characters and at most 30 characters' ) last_name = forms.CharField( label="Last Name", max_length=150, min_length=4, widget=forms.TextInput(attrs={'placeholder': 'Last Name'}), help_text= 'should enter at least 4 characters and at most 150 characters') email = forms.EmailField( label="Email", max_length=150, widget=forms.EmailInput(attrs={'placeholder': 'Email'})) username = forms.CharField( label="Username", widget=forms.TextInput(attrs={'placeholder': 'Username'}), help_text= "Required. 150 characters or fewer.Letters,digits and @/./+/-/_ only.") password = forms.CharField( label="Password", min_length=8, widget=forms.PasswordInput(attrs={'placeholder': 'Password'}), help_text=[ "Your Password can't be too similar to your other personal information.", "Your Password must contain at least 8 characters." "Your Password can't be a commonly used password.", "Your Password can't be entirely numeric." ]) password1 = forms.CharField( label="Confirm Password", min_length=8, widget=forms.PasswordInput(attrs={'placeholder': 'Confirm Password'}), help_text="Enter the same password as before,for validtion.") errors_messages = { 'password_mismatch': "The two password fields didn’t match.", } class Meta: model = User fields = ['first_name', 'last_name', 'username', 'email', 'password'] def clean(self, *args, **kwargs): password = self.cleaned_data.get('password') password1 = self.cleaned_data.get('password1') email = self.cleaned_data.get('email') if password and password1 and password != password1: raise forms.ValidationError( self.errors_messages['password_mismatch'], code='password_mismatch') if User.objects.filter(email=email).exists(): raise forms.ValidationError( 'Please use another Email,That is already taken') return super(UserRegisterForm, self).clean(*args, **kwargs) def save(self, commit=True): user = super().save(commit=False) user.set_password(self.cleaned_data['password']) if commit: user.save() return user