Skip to content

Commit b96f947

Browse files
committed
Merge branch 'main' of github.com:Jesulayomy/SCHub
2 parents c2d5874 + 2db0b2f commit b96f947

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+194
-92
lines changed

app/core/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
path("schema/", SpectacularAPIView.as_view(), name="api-schema"),
2727
path("token/", views.UserTokenObtainPairView.as_view(), name="token"),
2828
path("token/refresh/", TokenRefreshView.as_view(), name="token-refresh"),
29+
path("authenticated/", views.authenticated, name="authenticated"),
2930
path("status/", views.api_status, name="status"),
3031
path("user-stats/", views.user_stats, name="user_stats"),
3132
path("users/", views.UserList.as_view(), name="user_list"),

app/core/views.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# from django.views.decorators.csrf import csrf_exempt
55
from rest_framework.permissions import (
66
# AllowAny,
7-
# IsAuthenticated,
7+
IsAuthenticated,
88
IsAuthenticatedOrReadOnly,
99
# IsAdminUser,
1010
)
@@ -73,6 +73,18 @@ def user_stats(request):
7373
)
7474

7575

76+
@api_view(["GET"])
77+
@permission_classes([])
78+
def authenticated(request):
79+
"""Returns True if user is authenticated"""
80+
if request.user.is_authenticated:
81+
serialized = UserSerializer(request.user)
82+
return Response(
83+
{"detail": "User is authenticated", "user": serialized.data}
84+
)
85+
return Response({"detail": "User is not authenticated", "user": None})
86+
87+
7688
class UserTokenObtainPairView(TokenObtainPairView):
7789
serializer_class = UserTokenObtainPairSerializer
7890

@@ -106,7 +118,7 @@ def create(self, request, *args, **kwargs):
106118
class UserDetail(APIView):
107119
"""User retrieve, update and delete"""
108120

109-
permission_classes = [IsOwnerOrStaffOrAdminOrReadOnly]
121+
permission_classes = [IsAuthenticated, IsOwnerOrStaffOrAdminOrReadOnly]
110122
serializer_class = UserSerializer
111123

112124
def get(self, request, pk):

app/school/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def create(self, request, *args, **kwargs):
6969
self.perform_create(serializer)
7070

7171
data = {
72-
"detail": "Course created successfully",
73-
"course": serializer.data,
72+
"detail": "Department created successfully",
73+
"department": serializer.data,
7474
}
7575
return Response(data, status=status.HTTP_201_CREATED)
7676

app/schub/settings.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
# SECURITY WARNING: don't run with debug turned on in production!
3333
DEBUG = True
3434

35-
ALLOWED_HOSTS = []
35+
# ALLOWED_HOSTS = []
3636

3737

3838
# Application definition
@@ -47,6 +47,7 @@
4747
"rest_framework",
4848
"rest_framework.authtoken",
4949
"rest_framework_simplejwt",
50+
"corsheaders",
5051
"drf_spectacular",
5152
"core.apps.CoreConfig",
5253
"school.apps.SchoolConfig",
@@ -55,6 +56,7 @@
5556
MIDDLEWARE = [
5657
"django.middleware.security.SecurityMiddleware",
5758
"django.contrib.sessions.middleware.SessionMiddleware",
59+
"corsheaders.middleware.CorsMiddleware",
5860
"django.middleware.common.CommonMiddleware",
5961
"django.middleware.csrf.CsrfViewMiddleware",
6062
"django.contrib.auth.middleware.AuthenticationMiddleware",
@@ -148,7 +150,7 @@
148150
"rest_framework.permissions.IsAuthenticated",
149151
],
150152
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
151-
"PAGE_SIZE": 2,
153+
"PAGE_SIZE": 50,
152154
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
153155
# 'TOKEN_OBTAIN_SERIALIZER': 'core.serializers.UserTokenObtainPairSerializer',
154156
}
@@ -169,3 +171,6 @@
169171
"REFRESH_TOKEN_LIFETIME": timedelta(days=7),
170172
"AUTH_HEADER_TYPES": ("Token",),
171173
}
174+
175+
CORS_ALLOWED_ORIGINS = ["http://localhost:3000", "http://localhost:8000"]
176+
CORS_ALLOW_CREDENTIALS = True

SCHub-API-docs/docs/API Description/Admins/Create_a_new_admin.md renamed to mkdocs/docs/API Description/Admins/Create_a_new_admin.md

Lines changed: 0 additions & 1 deletion

SCHub-API-docs/docs/API Description/Admins/Delete_an_admin.md renamed to mkdocs/docs/API Description/Admins/Delete_an_admin.md

Lines changed: 0 additions & 1 deletion

SCHub-API-docs/docs/API Description/Admins/Retrieve_all_admins.md renamed to mkdocs/docs/API Description/Admins/Retrieve_all_admins.md

Lines changed: 0 additions & 1 deletion

SCHub-API-docs/docs/API Description/Admins/Retrieve_an_admin.md renamed to mkdocs/docs/API Description/Admins/Retrieve_an_admin.md

Lines changed: 0 additions & 1 deletion

SCHub-API-docs/docs/API Description/Admins/Update_an_admin.md renamed to mkdocs/docs/API Description/Admins/Update_an_admin.md

Lines changed: 0 additions & 1 deletion

0 commit comments

Comments
 (0)