File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 11from django .conf import settings
22from django .contrib .auth import authenticate , get_user_model
3+ from django .contrib .auth import password_validation
4+ from django .core import exceptions
35from django .utils .translation import gettext as _
46
57from rest_framework import serializers
@@ -24,6 +26,23 @@ class Meta:
2426 'password' : {'style' : {'input_type' : 'password' }},
2527 }
2628
29+ def validate (self , data ):
30+ password = data ['password' ]
31+
32+ # Create user object without saving it to get extra checks by validators
33+ user = User (** data )
34+
35+ errors = {}
36+ try :
37+ password_validation .validate_password (password = password , user = user )
38+ except exceptions .ValidationError as e :
39+ errors ['password' ] = list (e .messages )
40+
41+ if errors :
42+ raise serializers .ValidationError (errors )
43+
44+ return data
45+
2746 def create (self , validated_data ):
2847 return User .objects .create_user (
2948 email = validated_data ['email' ],
You can’t perform that action at this time.
0 commit comments