Brought back pass verification + added test

This commit is contained in:
mario 2016-01-05 14:56:11 +01:00
parent ec91620550
commit 99c4dc9d05
4 changed files with 25 additions and 9 deletions

View File

@ -51,7 +51,8 @@ Registration
- /rest-auth/registration/ (POST) - /rest-auth/registration/ (POST)
- username - username
- password - password1
- password2
- email - email
- /rest-auth/registration/verify-email/ (POST) - /rest-auth/registration/verify-email/ (POST)

View File

@ -124,9 +124,11 @@ class RegisterSerializer(serializers.Serializer):
username = serializers.CharField( username = serializers.CharField(
max_length=get_username_max_length(), max_length=get_username_max_length(),
min_length=allauth_settings.USERNAME_MIN_LENGTH, min_length=allauth_settings.USERNAME_MIN_LENGTH,
required=allauth_settings.USERNAME_REQUIRED) required=allauth_settings.USERNAME_REQUIRED
)
email = serializers.EmailField(required=allauth_settings.EMAIL_REQUIRED) email = serializers.EmailField(required=allauth_settings.EMAIL_REQUIRED)
password = serializers.CharField(required=True, write_only=True) password1 = serializers.CharField(required=True, write_only=True)
password2 = serializers.CharField(required=True, write_only=True)
def validate_username(self, username): def validate_username(self, username):
username = get_adapter().clean_username(username) username = get_adapter().clean_username(username)
@ -140,16 +142,21 @@ class RegisterSerializer(serializers.Serializer):
"A user is already registered with this e-mail address.") "A user is already registered with this e-mail address.")
return email return email
def validate_password(self, password): def validate_password1(self, password):
return get_adapter().clean_password(password) return get_adapter().clean_password(password)
def validate(self, data):
if data['password1'] != data['password2']:
raise serializers.ValidationError("The two password fields didn't match.")
return data
def custom_signup(self, request, user): def custom_signup(self, request, user):
pass pass
def get_cleaned_data(self): def get_cleaned_data(self):
return { return {
'username': self.validated_data.get('username', ''), 'username': self.validated_data.get('username', ''),
'password1': self.validated_data.get('password', ''), 'password1': self.validated_data.get('password1', ''),
'email': self.validated_data.get('email', '') 'email': self.validated_data.get('email', '')
} }

View File

@ -28,7 +28,8 @@ class APITestCase1(TestCase, BaseAPITestCase):
# data without user profile # data without user profile
REGISTRATION_DATA = { REGISTRATION_DATA = {
"username": USERNAME, "username": USERNAME,
"password": PASS, "password1": PASS,
"password2": PASS
} }
REGISTRATION_DATA_WITH_EMAIL = REGISTRATION_DATA.copy() REGISTRATION_DATA_WITH_EMAIL = REGISTRATION_DATA.copy()
@ -271,6 +272,12 @@ class APITestCase1(TestCase, BaseAPITestCase):
self._login() self._login()
self._logout() self._logout()
def test_registration_with_invalid_password(self):
data = self.REGISTRATION_DATA.copy()
data['password2'] = 'foobar'
self.post(self.register_url, data=data, status_code=400)
@override_settings( @override_settings(
ACCOUNT_EMAIL_VERIFICATION='mandatory', ACCOUNT_EMAIL_VERIFICATION='mandatory',
ACCOUNT_EMAIL_REQUIRED=True ACCOUNT_EMAIL_REQUIRED=True

View File

@ -21,7 +21,8 @@ class TestSocialAuth(TestCase, BaseAPITestCase):
EMAIL = "person1@world.com" EMAIL = "person1@world.com"
REGISTRATION_DATA = { REGISTRATION_DATA = {
"username": USERNAME, "username": USERNAME,
"password": PASS, "password1": PASS,
"password2": PASS,
"email": EMAIL "email": EMAIL
} }