Ticket #7507: 7507.diff

File 7507.diff, 5.9 KB (added by SmileyChris, 7 years ago)

Patch for r8061 (post NFA merge)

  • django/contrib/auth/forms.py

     
    1414        error_message = _("This value must contain only letters, numbers and underscores."))
    1515    password1 = forms.CharField(label=_("Password"), max_length=60, widget=forms.PasswordInput)
    1616    password2 = forms.CharField(label=_("Password confirmation"), max_length=60, widget=forms.PasswordInput)
    17    
     17
    1818    class Meta:
    1919        model = User
    2020        fields = ("username",)
    21    
     21
    2222    def clean_username(self):
    2323        username = self.cleaned_data["username"]
    2424        try:
     
    2626        except User.DoesNotExist:
    2727            return username
    2828        raise forms.ValidationError(_("A user with that username already exists."))
    29    
     29
    3030    def clean_password2(self):
    3131        password1 = self.cleaned_data["password1"]
    3232        password2 = self.cleaned_data["password2"]
    3333        if password1 != password2:
    3434            raise forms.ValidationError(_("The two password fields didn't match."))
    3535        return password2
    36    
     36
    3737    def save(self, commit=True):
    3838        user = super(UserCreationForm, self).save(commit=False)
    3939        user.set_password(self.cleaned_data["password1"])
     
    4646    Base class for authenticating users. Extend this to get a form that accepts
    4747    username/password logins.
    4848    """
    49     username = forms.CharField(label=_("Username"), max_length=30)
    50     password = forms.CharField(label=_("Password"), max_length=30, widget=forms.PasswordInput)
    51    
     49    username = forms.CharField(label=_("Username"))
     50    password = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
     51
    5252    def __init__(self, request=None, *args, **kwargs):
    5353        """
    5454        If request is passed in, the form will validate that cookies are
     
    5959        self.request = request
    6060        self.user_cache = None
    6161        super(AuthenticationForm, self).__init__(*args, **kwargs)
    62    
     62
    6363    def clean(self):
    6464        username = self.cleaned_data.get('username')
    6565        password = self.cleaned_data.get('password')
    66        
     66
    6767        if username and password:
    6868            self.user_cache = authenticate(username=username, password=password)
    6969            if self.user_cache is None:
    7070                raise forms.ValidationError(_("Please enter a correct username and password. Note that both fields are case-sensitive."))
    7171            elif not self.user_cache.is_active:
    7272                raise forms.ValidationError(_("This account is inactive."))
    73        
     73
    7474        # TODO: determine whether this should move to its own method.
    7575        if self.request:
    7676            if not self.request.session.test_cookie_worked():
    7777                raise forms.ValidationError(_("Your Web browser doesn't appear to have cookies enabled. Cookies are required for logging in."))
    78        
     78
    7979        return self.cleaned_data
    80    
     80
    8181    def get_user_id(self):
    8282        if self.user_cache:
    83             return self.user_cache.id
     83            return self.user_cache.pk
    8484        return None
    85    
     85
    8686    def get_user(self):
    8787        return self.user_cache
    8888
    8989class PasswordResetForm(forms.Form):
    9090    email = forms.EmailField(label=_("E-mail"), max_length=40)
    91    
     91
    9292    def clean_email(self):
    9393        """
    9494        Validates that a user exists with the given e-mail address.
     
    9797        self.users_cache = User.objects.filter(email__iexact=email)
    9898        if len(self.users_cache) == 0:
    9999            raise forms.ValidationError(_("That e-mail address doesn't have an associated user account. Are you sure you've registered?"))
    100    
     100
    101101    def save(self, domain_override=None, email_template_name='registration/password_reset_email.html'):
    102102        """
    103103        Calculates a new password randomly and sends it to the user.
     
    131131    old_password = forms.CharField(label=_("Old password"), max_length=30, widget=forms.PasswordInput)
    132132    new_password1 = forms.CharField(label=_("New password"), max_length=30, widget=forms.PasswordInput)
    133133    new_password2 = forms.CharField(label=_("New password confirmation"), max_length=30, widget=forms.PasswordInput)
    134    
     134
    135135    def __init__(self, user, *args, **kwargs):
    136136        self.user = user
    137137        super(PasswordChangeForm, self).__init__(*args, **kwargs)
    138    
     138
    139139    def clean_old_password(self):
    140140        """
    141141        Validates that the old_password field is correct.
     
    144144        if not self.user.check_password(old_password):
    145145            raise forms.ValidationError(_("Your old password was entered incorrectly. Please enter it again."))
    146146        return old_password
    147    
     147
    148148    def clean_new_password2(self):
    149149        password1 = self.cleaned_data.get('new_password1')
    150150        password2 = self.cleaned_data.get('new_password2')
     
    152152            if password1 != password2:
    153153                raise forms.ValidationError(_("The two password fields didn't match."))
    154154        return password2
    155    
     155
    156156    def save(self, commit=True):
    157157        self.user.set_password(self.cleaned_data['new_password1'])
    158158        if commit:
     
    165165    """
    166166    password1 = forms.CharField(label=_("Password"), max_length=60, widget=forms.PasswordInput)
    167167    password2 = forms.CharField(label=_("Password (again)"), max_length=60, widget=forms.PasswordInput)
    168    
     168
    169169    def __init__(self, user, *args, **kwargs):
    170170        self.user = user
    171171        super(AdminPasswordChangeForm, self).__init__(*args, **kwargs)
    172    
     172
    173173    def clean_password2(self):
    174174        password1 = self.cleaned_data.get('password1')
    175175        password2 = self.cleaned_data.get('password2')
     
    177177            if password1 != password2:
    178178                raise forms.ValidationError(_("The two password fields didn't match."))
    179179        return password2
    180    
     180
    181181    def save(self, commit=True):
    182182        """
    183183        Saves the new password.
Back to Top