2010-08-07 9 views
1

비밀 번호 재설정 양식에 대한 새로운 방법 (길이, 문자, ...)에 대한 몇 가지 테스트를 만들기 위해 내 자신의 방법을 쓰고 싶습니다.비밀 번호 재설정 양식, 자신의 깨끗한 방법

class PasswordResetForm(SetPasswordForm): 
    def clean(self): 
    if 'newpassword1' in self.cleaned_data and 'newpassword2' in self.cleaned_data: 
     if self.cleaned_data['newpassword1'] != self.cleaned_data['newpassword2']: 
     raise forms.ValidationError(("The two password fields didn't match.")) 

     #here the passwords entered are the same 
     if len(self.cleaned_data['newpassword1']) < 8: 
     raise forms.ValidationError(("Your password has to be at least 8 characters long")) 

     if not re.search('\d+', self.cleaned_data['newpassword1']) or not re.search('([a-zA-Z])+', self.cleaned_data['new password1']): 
     raise forms.ValidationError(("Your password needs to contain at least one number and one character")) 

     return self.cleaned_data 

을하고 urls.py에서 나는이 추가 : 그래서 난 내 forms.py에이 클래스를 추가

url(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', django.contrib.auth.views.password_reset_confirm, {'template_name':'registration/password_reset_confirm.html', 
                                    'set_password_form': PasswordResetForm}) 

을하지만 내 자신의 깨끗한 메서드가 호출되지 않습니다. 이게 뭐니?

답변

0

오류가 발견되었습니다. 그것은 내 urls.py에서 실수 였어. 그것은 다음과 같아야합니다 :

url(r'^password/reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',django.contrib.auth.views.password_reset_confirm,{'template_name':'registration/password_reset_confirm.html','set_password_form': PasswordResetForm}) 

나는 왜 아직도 암호 재설정 양식이 있고 404가 아닌지 모르겠다. 누군가가 말해 줄 수 있습니다. 표준 재설정 양식을 사용할 수있는 방법이 여전히 있을지 모르지만 조금 걱정됩니다.

0

이 답변이 바보 보일 수 있습니다 그리고 난 정당성이없는하지만 난 같은 문제에 달려 내가 모든 clean_data에 대한

self.cleaned_data.get('newpassword1') 

하여

self.cleaned_data['newpassword1'] 

를 대체하여 그것을 해결 설정 :

class PasswordResetForm(SetPasswordForm): 
def clean(self): 
    cleaned_data = self.cleaned_data 
    if 'newpassword1' in cleaned_data and 'newpassword2' in cleaned_data: 
    if cleaned_data.get('newpassword1') != cleaned_data.get('newpassword2'): 
     raise forms.ValidationError(("The two password fields didn't match.")) 


    if len(cleaned_data.get('newpassword1')) < 8: 
     raise forms.ValidationError(("Your password has to be at least 8 characters long")) 

    if not re.search('\d+', cleaned_data.get('newpassword1')) or not re.search('([a-zA-Z])+', cleaned_data.get('new password1')): 
     raise forms.ValidationError(("Your password needs to contain at least one number and one character")) 

    return cleaned_data 
+0

나를 위해하지 않았습니다. 여전히 같은 문제. breakpoint를 clean 함수로 설정하면 호출되지 않습니다. 그래서 문제는 다른 곳에서해야합니다. – Kai

관련 문제