Browse Source
feat(account): add web user registration endpoint and serializer
feat(account): add web user registration endpoint and serializer
- Introduced a new endpoint for web user registration at 'web/register/'. - Created WebUserRegisterSerializer to handle user registration with email and password validation. - Enhanced UserVerifyView to support password handling during user creation and verification.master
3 changed files with 72 additions and 4 deletions
@ -0,0 +1,29 @@ |
|||
from rest_framework import serializers |
|||
from django.contrib.auth.password_validation import validate_password |
|||
from apps.account.models import User |
|||
|
|||
|
|||
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(): |
|||
raise serializers.ValidationError("This email is already registered.") |
|||
return normalized_email |
|||
|
|||
def create(self, validated_data): |
|||
user = super().create(validated_data) |
|||
return user |
|||
|
|||
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue