mirror of
				https://gitlab.crans.org/bde/nk20
				synced 2025-11-04 09:12:11 +01:00 
			
		
		
		
	Add simple view to give OAuth information
Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
This commit is contained in:
		@@ -5,6 +5,7 @@ from django.conf import settings
 | 
				
			|||||||
from django.conf.urls import url, include
 | 
					from django.conf.urls import url, include
 | 
				
			||||||
from rest_framework import routers
 | 
					from rest_framework import routers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from .views import UserInformationView
 | 
				
			||||||
from .viewsets import ContentTypeViewSet, UserViewSet
 | 
					from .viewsets import ContentTypeViewSet, UserViewSet
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Routers provide an easy way of automatically determining the URL conf.
 | 
					# Routers provide an easy way of automatically determining the URL conf.
 | 
				
			||||||
@@ -47,5 +48,6 @@ app_name = 'api'
 | 
				
			|||||||
# Additionally, we include login URLs for the browsable API.
 | 
					# Additionally, we include login URLs for the browsable API.
 | 
				
			||||||
urlpatterns = [
 | 
					urlpatterns = [
 | 
				
			||||||
    url('^', include(router.urls)),
 | 
					    url('^', include(router.urls)),
 | 
				
			||||||
 | 
					    url('me', UserInformationView.as_view()),
 | 
				
			||||||
    url('^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
 | 
					    url('^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										17
									
								
								apps/api/views.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								apps/api/views.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					# Copyright (C) 2018-2021 by BDE ENS Paris-Saclay
 | 
				
			||||||
 | 
					# SPDX-License-Identifier: GPL-3.0-or-later
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from django.contrib.auth.models import User
 | 
				
			||||||
 | 
					from rest_framework.generics import RetrieveAPIView
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from .serializers import UserSerializer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class UserInformationView(RetrieveAPIView):
 | 
				
			||||||
 | 
					    serializer_class = UserSerializer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_queryset(self):
 | 
				
			||||||
 | 
					        return User.objects.filter(pk=self.request.user.pk)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_object(self):
 | 
				
			||||||
 | 
					        return self.request.user
 | 
				
			||||||
		Reference in New Issue
	
	Block a user