You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

31 lines
1.1 KiB

from rest_framework import serializers
from django.contrib.auth.password_validation import validate_password
from apps.account.models import User
from apps.account.utils import get_localized_msg
class WebUserRegisterSerializer(serializers.ModelSerializer):
password = serializers.CharField(write_only=True, validators=[validate_password])
fcm = serializers.CharField(required=False, allow_blank=True, allow_null=True)
email = serializers.EmailField()
class Meta:
model = User
fields = ['id', 'fullname', 'email', 'password', 'fcm']
extra_kwargs = {
'fullname': {'required': True},
'email': {'required': True},
}
def validate_email(self, value):
normalized_email = User.objects.normalize_email(value)
if User.objects.filter(email=normalized_email).exists():
msg = get_localized_msg('email_already_registered', self.context.get('request'))
raise serializers.ValidationError(msg)
return normalized_email
def create(self, validated_data):
user = super().create(validated_data)
return user