mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2024-11-26 02:53:46 +03:00
Added non existing e-mail validation on password reset
+ small cleanup
This commit is contained in:
parent
52283aed70
commit
d9b8f3faf6
|
@ -94,7 +94,7 @@ class UserDetailsSerializer(serializers.ModelSerializer):
|
|||
User model w/o password
|
||||
"""
|
||||
class Meta:
|
||||
model = get_user_model()
|
||||
model = UserModel
|
||||
fields = ('username', 'email', 'first_name', 'last_name')
|
||||
read_only_fields = ('email', )
|
||||
|
||||
|
@ -113,7 +113,11 @@ class PasswordResetSerializer(serializers.Serializer):
|
|||
# Create PasswordResetForm with the serializer
|
||||
self.reset_form = self.password_reset_form_class(data=self.initial_data)
|
||||
if not self.reset_form.is_valid():
|
||||
raise serializers.ValidationError('Error')
|
||||
raise serializers.ValidationError(_('Error'))
|
||||
|
||||
if not UserModel.objects.filter(email=value).exists():
|
||||
raise serializers.ValidationError(_('Invalid e-mail address'))
|
||||
|
||||
return value
|
||||
|
||||
def save(self):
|
||||
|
|
|
@ -160,12 +160,8 @@ class APITestCase1(TestCase, BaseAPITestCase):
|
|||
result = {}
|
||||
from django.utils.encoding import force_bytes
|
||||
from django.contrib.auth.tokens import default_token_generator
|
||||
from django import VERSION
|
||||
if VERSION[1] == 5:
|
||||
from django.utils.http import int_to_base36
|
||||
result['uid'] = int_to_base36(user.pk)
|
||||
else:
|
||||
from django.utils.http import urlsafe_base64_encode
|
||||
|
||||
result['uid'] = urlsafe_base64_encode(force_bytes(user.pk))
|
||||
result['token'] = default_token_generator.make_token(user)
|
||||
return result
|
||||
|
@ -338,6 +334,15 @@ class APITestCase1(TestCase, BaseAPITestCase):
|
|||
}
|
||||
self.post(self.login_url, data=payload, status_code=200)
|
||||
|
||||
def test_password_reset_with_invalid_email(self):
|
||||
get_user_model().objects.create_user(self.USERNAME, self.EMAIL, self.PASS)
|
||||
|
||||
# call password reset
|
||||
mail_count = len(mail.outbox)
|
||||
payload = {'email': 'nonexisting@email.com'}
|
||||
self.post(self.password_reset_url, data=payload, status_code=400)
|
||||
self.assertEqual(len(mail.outbox), mail_count)
|
||||
|
||||
def test_user_details(self):
|
||||
user = get_user_model().objects.create_user(self.USERNAME, self.EMAIL, self.PASS)
|
||||
payload = {
|
||||
|
|
Loading…
Reference in New Issue
Block a user