File tree 1 file changed +19
-0
lines changed
1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 1
1
from django .conf import settings
2
2
from django .contrib .auth import authenticate , get_user_model
3
+ from django .contrib .auth import password_validation
4
+ from django .core import exceptions
3
5
from django .utils .translation import gettext as _
4
6
5
7
from rest_framework import serializers
@@ -24,6 +26,23 @@ class Meta:
24
26
'password' : {'style' : {'input_type' : 'password' }},
25
27
}
26
28
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
+
27
46
def create (self , validated_data ):
28
47
return User .objects .create_user (
29
48
email = validated_data ['email' ],
You can’t perform that action at this time.
0 commit comments