We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 089f0bb commit d508b94Copy full SHA for d508b94
rest_authtoken/serializers.py
@@ -26,7 +26,23 @@ class Meta:
26
},
27
}
28
29
- def validate_password(self, value):
+ @staticmethod
30
+ def validate_username(value):
31
+ """
32
+ Make sure that no user with this natural key exists.
33
+ This can be used to make usernames case-insensitive, e.g.,
34
+ disallow the registration of two different usernames which
35
+ are equal but with different case.
36
37
+ try:
38
+ user = get_user_model().objects.get_by_natural_key(value)
39
+ except get_user_model().DoesNotExist:
40
+ return value
41
+ else:
42
+ raise ValidationError('already exists')
43
+
44
45
+ def validate_password(value):
46
if len(value) < 6:
47
raise ValidationError('password too short')
48
return value
0 commit comments