# password2 = serializers.CharField(style={'input_type':'password'},write_only=True)
class Meta:
model = User
fields = ['username','password','email','first_name','last_name']
extra_kwargs ={
"password":{"write_only":True},
"email":{
"required":True,
"allow_blank":False,
"validators":[
validators.UniqueValidator(
User.objects.all(),"A user with that Email already exists"
)
]
}
}
# def validate(self,attrs):
# if attrs['password'] != attrs['password2']:
# raise serializers.validationError({"password":"password fields didn't match"})
def create(self,validated_data):
username = validated_data.get('username')
password = validated_data.get('password')
email = validated_data.get('email')
first_name = validated_data.get('first_name')
last_name = validated_data.get('last_name')
user = User.objects.create(
username=username,
password=password,
email=email,
first_name=first_name,
last_name=last_name,
)
user.save()
return user
when I try to new register new user form the API,the saved user doesn't have it's password hashed which is creating a problem while logging in.You can see the difference between admin and new_user.To create a user model I have inherited a Abstract user class.You can also check my register serializer
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d9adde23-46cd-40bf-babc-ced3d4b9d9ban%40googlegroups.com.
No comments:
Post a Comment