Commit 5de2a7b9 authored by David Haynes's avatar David Haynes 🙆

Expose more user session info at the API level

- /auth/status

    "username": "dhaynes3",
    "is_authenticated": true,
    "is_registered": false,
    "is_approved": false,
    "is_blocked": false
parent 96998a15
......@@ -49,6 +49,10 @@ class URLViewSet(viewsets.ModelViewSet):
class CustomAuthToken(ObtainAuthToken):
Custom endpoint to provide the currently logged in user's API token.
authentication_classes = (SessionAuthentication,)
permission_classes = (IsAuthenticated,)
......@@ -63,6 +67,16 @@ class GetSessionInfo(APIView):
permission_classes = (AllowAny,)
def get(self, request, *args, **kwargs):
if not request.user.is_anonymous:
session_info = {
"username": request.user.username,
"is_authenticated": request.user.is_authenticated,
"is_registered": request.user.registereduser.registered,
"is_approved": request.user.registereduser.approved,
"is_blocked": request.user.registereduser.blocked,
session_info = {
"username": request.user.username,
"is_authenticated": request.user.is_authenticated,
......@@ -73,6 +87,8 @@ class GetSessionInfo(APIView):
def redirection(request, short):
This view redirects a user based on the short URL they requested.
The meat and potatoes of Go.
# Get the URL object that relates to the requested Go link
url = get_object_or_404(URL, short__iexact=short)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment