Skip to content

Commit 99c4dc9

Browse files
committed
Brought back pass verification + added test
1 parent ec91620 commit 99c4dc9

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

docs/api_endpoints.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ Registration
5151
- /rest-auth/registration/ (POST)
5252

5353
- username
54-
- password
54+
- password1
55+
- password2
5556
- email
5657

5758
- /rest-auth/registration/verify-email/ (POST)

rest_auth/registration/serializers.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,13 @@ def validate(self, attrs):
122122

123123
class RegisterSerializer(serializers.Serializer):
124124
username = serializers.CharField(
125-
max_length=get_username_max_length(),
126-
min_length=allauth_settings.USERNAME_MIN_LENGTH,
127-
required=allauth_settings.USERNAME_REQUIRED)
125+
max_length=get_username_max_length(),
126+
min_length=allauth_settings.USERNAME_MIN_LENGTH,
127+
required=allauth_settings.USERNAME_REQUIRED
128+
)
128129
email = serializers.EmailField(required=allauth_settings.EMAIL_REQUIRED)
129-
password = serializers.CharField(required=True, write_only=True)
130+
password1 = serializers.CharField(required=True, write_only=True)
131+
password2 = serializers.CharField(required=True, write_only=True)
130132

131133
def validate_username(self, username):
132134
username = get_adapter().clean_username(username)
@@ -140,16 +142,21 @@ def validate_email(self, email):
140142
"A user is already registered with this e-mail address.")
141143
return email
142144

143-
def validate_password(self, password):
145+
def validate_password1(self, password):
144146
return get_adapter().clean_password(password)
145147

148+
def validate(self, data):
149+
if data['password1'] != data['password2']:
150+
raise serializers.ValidationError("The two password fields didn't match.")
151+
return data
152+
146153
def custom_signup(self, request, user):
147154
pass
148155

149156
def get_cleaned_data(self):
150157
return {
151158
'username': self.validated_data.get('username', ''),
152-
'password1': self.validated_data.get('password', ''),
159+
'password1': self.validated_data.get('password1', ''),
153160
'email': self.validated_data.get('email', '')
154161
}
155162

rest_auth/tests/test_api.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ class APITestCase1(TestCase, BaseAPITestCase):
2828
# data without user profile
2929
REGISTRATION_DATA = {
3030
"username": USERNAME,
31-
"password": PASS,
31+
"password1": PASS,
32+
"password2": PASS
3233
}
3334

3435
REGISTRATION_DATA_WITH_EMAIL = REGISTRATION_DATA.copy()
@@ -271,6 +272,12 @@ def test_registration(self):
271272
self._login()
272273
self._logout()
273274

275+
def test_registration_with_invalid_password(self):
276+
data = self.REGISTRATION_DATA.copy()
277+
data['password2'] = 'foobar'
278+
279+
self.post(self.register_url, data=data, status_code=400)
280+
274281
@override_settings(
275282
ACCOUNT_EMAIL_VERIFICATION='mandatory',
276283
ACCOUNT_EMAIL_REQUIRED=True

rest_auth/tests/test_social.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class TestSocialAuth(TestCase, BaseAPITestCase):
2121
2222
REGISTRATION_DATA = {
2323
"username": USERNAME,
24-
"password": PASS,
24+
"password1": PASS,
25+
"password2": PASS,
2526
"email": EMAIL
2627
}
2728

0 commit comments

Comments
 (0)