Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check loggedin #91

Merged
merged 5 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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

Expand All @@ -26,6 +27,7 @@
"openid",
]


REDIRECT_URL = f"{settings.BASE_URL}/calendar/redirect/"
API_SERVICE_NAME = "calendar"
API_VERSION = "v3"
Expand Down Expand Up @@ -88,6 +90,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 = {
Expand Down
1 change: 1 addition & 0 deletions webapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
),
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
],
}

Expand Down
Loading