Add /me API endpoint

This commit is contained in:
Raphael Michel
2018-11-09 11:16:41 +01:00
parent 901953d988
commit 584ced87db
3 changed files with 54 additions and 1 deletions

View File

@@ -7,7 +7,7 @@ from rest_framework import routers
from pretix.api.views import cart
from .views import (
checkin, device, event, item, oauth, order, organizer, voucher,
checkin, device, event, item, oauth, order, organizer, user, voucher,
waitinglist, webhooks,
)
@@ -72,4 +72,5 @@ urlpatterns = [
url(r"^device/update$", device.UpdateView.as_view(), name="device.update"),
url(r"^device/roll$", device.RollKeyView.as_view(), name="device.roll"),
url(r"^device/revoke$", device.RevokeKeyView.as_view(), name="device.revoke"),
url(r"^me$", user.MeView.as_view(), name="user.me"),
]

View File

@@ -0,0 +1,16 @@
from oauth2_provider.contrib.rest_framework import OAuth2Authentication
from rest_framework.authentication import SessionAuthentication
from rest_framework.response import Response
from rest_framework.views import APIView
class MeView(APIView):
authentication_classes = (SessionAuthentication, OAuth2Authentication)
def get(self, request, format=None):
return Response({
'email': request.user.email,
'fullname': request.user.fullname,
'locale': request.user.locale,
'timezone': request.user.timezone
})