Git Product home page Git Product logo

Comments (4)

PhilipGarnero avatar PhilipGarnero commented on June 19, 2024

What do you mean by registration ?
An user object is automatically created if you use an external token but I can't really handle registration as some people will not have the same fields, actions and behaviors for their user.

I can help you by posting some examples but I will not implement it in this package unless wanted by a lot of people.

# You can use this as a simple serializer
class UserSerializer(serializers.ModelSerializer):
    is_active = serializers.CharField(read_only=True)
    date_joined = serializers.DateTimeField(read_only=True)

    class Meta:
        model = User
        fields = ('email', 'password', 'username', 'first_name', 'last_name', 'is_active', 'date_joined',)
        extra_kwargs = {'password': {'write_only': True}}

# And this viewset
class UserAPIView(GenericViewSet, RetrieveModelMixin, UpdateModelMixin, CreateModelMixin):
    """
    ### Interact with users

    - **Methods**:
        - list: *Post*
        - detail: *Get*, *Put*, *Patch*
        - me: *Get*
            - returns the current user
    - **Permissions**:
        - authenticated user required on detail
    - **Returns**:
        - the user
    """
    queryset = User.objects.all()
    serializer_class = UserSerializer
    permission_classes = [permissions.IsAuthenticated]

    def get_object(self):
        obj = super(UserAPIView, self).get_object()
        if obj != self.request.user:
            raise Http404
        return obj

    @list_route()
    def me(self, request):
        user = get_object_or_404(self.queryset, pk=request.user.id)
        serializer = self.serializer_class(user)
        return Response(serializer.data)

# Add these to your urls
    url(r'^api/', include('rest_framework_social_oauth2.urls')),
    url(r'^api/users/?$', UserAPIView.as_view({'post': 'create'}), name='user-list'),
    url(r'^api/users/me/?$', UserAPIView.as_view({'get': 'me'}), name='user-me'),
    url(r'^api/users/(?P<pk>\d+)$', UserAPIView.as_view({'get': 'retrieve', 'put': 'update', 'patch': 'partial_update'}), name='user-detail'),

from django-rest-framework-social-oauth2.

Guest007 avatar Guest007 commented on June 19, 2024

I mean creating new user from FB account's data

from django-rest-framework-social-oauth2.

PhilipGarnero avatar PhilipGarnero commented on June 19, 2024

This should work already. Python social auth is used in the authentication backend and will automatically create an user if it doesn't exist.

from django-rest-framework-social-oauth2.

PhilipGarnero avatar PhilipGarnero commented on June 19, 2024

I'm closing this since it's the current behavior.
Feel free to reopen if I didn't answer your questions.

from django-rest-framework-social-oauth2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.