Skip to content

Commit

Permalink
Merge pull request #91 from ruanclaudio/check-loggedin
Browse files Browse the repository at this point in the history
Check loggedin
ivancrneto authored Jul 30, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 64e3fd8 + c19c00e commit 4f27199
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion api/urls.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
urlpatterns = [
path("v1/calendar/init/", views.calendar_init_view, name="calendar_init"),
path("v1/calendar/token/", views.calendar_token, name="calendar_token"),
path("v1/user/return", views.user_json_return, name="test_user_return"),
path("v1/user/auth/", views.check_user_is_loggedin, name="check_user_loggedin"),
path("v1/user/info/", views.user_info_view, name="user_info"),
path("v1/user/return/", views.user_json_return, name="test_user_return"),
]
11 changes: 11 additions & 0 deletions api/views.py
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
from django.http import JsonResponse
from google.auth.transport.requests import Request
from google_auth_oauthlib.flow import Flow, InstalledAppFlow
from rest_framework import status
from rest_framework.authtoken.models import Token
from rest_framework.decorators import api_view

@@ -27,6 +28,7 @@
"openid",
]


REDIRECT_URL = f"{settings.BASE_URL}/calendar/redirect/"
API_SERVICE_NAME = "calendar"
API_VERSION = "v3"
@@ -89,6 +91,15 @@ def user_info_view(request):
return JsonResponse(serializer.data, safe=False)


@api_view(['GET'])
def check_user_is_loggedin(request):
session_key = request.session.session_key
if request.user.is_authenticated:
return JsonResponse({"session_key ": session_key}, status=status.HTTP_200_OK)
response_data = {"error": "user has been desconnected"}
return JsonResponse(response_data, status=status.HTTP_403_FORBIDDEN)


@api_view(["GET"])
def user_json_return(request):
user_info = {

0 comments on commit 4f27199

Please sign in to comment.