Skip to content

Commit

Permalink
Merge pull request #2 from Abramov0Alexandr/feature
Browse files Browse the repository at this point in the history
Ввел дополнительное поле при регистрации пользователя (подтверждение …
  • Loading branch information
Abramov0Alexandr committed Sep 24, 2023
2 parents 90c9d96 + 126690e commit 4ee82bb
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion custom_user/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ class CustomUserCreateSerializer(serializers.ModelSerializer):
"""
Сериализатор модели CustomUser.
Используется при вызове GET запросов в контроллере CustomUserCreateView
password_confirmation: поле для подтверждения введенного пароля. Обработка исключений происходит в методе create.
"""

password_confirmation = serializers.CharField(write_only=True)

class Meta:
model = CustomUser
fields = ('password', 'email', )
fields = ('email', 'password', 'password_confirmation', )

def create(self, validated_data):
"""
Expand All @@ -31,5 +34,13 @@ def create(self, validated_data):
:return: Создается новый экземпляр класса CustomUser
"""

password_confirmation = validated_data.pop('password_confirmation', None)

if password_confirmation is None:
raise serializers.ValidationError("Поле 'password_confirmation' обязательно")

if validated_data.get('password') != password_confirmation:
raise serializers.ValidationError("Пароль и его подтверждение не совпадают")

new_custom_user = CustomUser.objects.create_user(**validated_data)
return new_custom_user

0 comments on commit 4ee82bb

Please sign in to comment.