Wednesday, December 30, 2015

How change info about register user

In Django\contrib\auth\forms.py I have clas like below. When I use it and create a form to register a user with fields user, password, confirm password I have also info about correct characters to register user. How can I change this info?

class UserCreationForm(forms.ModelForm):
   
"""
    A form that creates a user, with no privileges, from the given username and
    password.
    """
    error_messages = {
       
'password_mismatch': _("The two password fields didn't match."),
   
}
    password1
= forms.CharField(label=_("Password"),
       
widget=forms.PasswordInput)
    password2
= forms.CharField(label=_("Password confirmation"),
       
widget=forms.PasswordInput,
       
help_text=_("Enter the same password as above, for verification."))

   
class Meta:
        model
= User
        fields
= ("username",)

   
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 save(self, commit=True):
       
user = super(UserCreationForm, self).save(commit=False)
       
user.set_password(self.cleaned_data["password1"])
       
if commit:
           
user.save()
       
return user


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/feda6714-4e74-42f9-a1f8-1d01f028549b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment