Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserSerializer(serializers.ModelSerializer):
- """Serializer to map the model instance into json format."""
- class Meta:
- """Map this serializer to a model and their fields."""
- model = User
- fields = ('id','username', 'mobile', 'password', 'first_name','last_name','middle_name','profile_pic','short_bio','friends_privacy','address_1','address_2','city','state','country','pin','verification_code','is_active','is_blocked','is_reported','date_created','date_modified') # ADD 'owner'
- extra_kwargs = {'password': {'write_only': True}}
- read_only_fields = ('date_created', 'date_modified','is_staff', 'is_superuser', 'is_active', 'date_joined',)
- def create(self, validated_data):
- mobile_ = validated_data['mobile']
- password_ = validated_data['password']
- username_ = validated_data['username']
- motp = self.context['request'].GET['motp']
- eotp = self.context['request'].GET['eotp']
- email_ = self.context['request'].GET['email']
- mflag = api.views.checkOTP_(mobile_,motp)
- eflag = api.views.checkOTP_(email_,eotp)
- if (mflag and eflag):
- user = User(
- username=username_,
- email =email_,
- password = make_password(password_),
- mobile = mobile_,
- )
- user.set_password(validated_data['password'])
- user.save()
- return user
- class UserView2(viewsets.ModelViewSet):
- queryset = User.objects.all()
- serializer_class = UserSerializer
- model = User
- def get_permissions(self):
- # allow non-authenticated user to create via POST
- return (AllowAny() if self.request.method == 'POST'
- else IsStaffOrTargetUser()),
Add Comment
Please, Sign In to add comment