Fakultas Ilmu Komputer UI

Commit c818da8e authored by annisadevin's avatar annisadevin
Browse files

Mengatur cors dan menambahkan api get resource user

parent 2ed696f9
Pipeline #124028 passed with stages
in 5 minutes and 14 seconds
......@@ -38,13 +38,14 @@ PRODUCTION = os.getenv('DATABASE_URL') is not None
# set this to True.
DEBUG = not PRODUCTION
HEROKU_APP_NAME = os.getenv('HEROKU_APP_NAME', '')
ALLOWED_HOSTS = [f'{HEROKU_APP_NAME}.herokuapp.com']
if not PRODUCTION:
ALLOWED_HOSTS += ['.localhost', '127.0.0.1', '[::1]']
ALLOWED_HOSTS = [
'*'
]
CORS_ALLOWED_ORIGINS = [
"https://remindme-frontend.herokuapp.com",
"http://localhost:3000",
]
# Application definition
......@@ -55,8 +56,10 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
'main',
'oauth',
'rest_framework',
'rest_framework_simplejwt',
'rest_framework_simplejwt.token_blacklist',
]
......@@ -70,6 +73,7 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware',
]
ROOT_URLCONF = 'auth_remindme.urls'
......@@ -209,4 +213,7 @@ SIMPLE_JWT = {
'SLIDING_TOKEN_REFRESH_EXP_CLAIM': 'refresh_exp',
'SLIDING_TOKEN_LIFETIME': timedelta(minutes=5),
'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=1),
}
\ No newline at end of file
}
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
\ No newline at end of file
from django.urls import path
from django.urls import path, include
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
......@@ -9,10 +9,11 @@ from . import views
app_name = 'oauth'
urlpatterns = [
path('api-auth/', include('rest_framework.urls')),
path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
path('api/token/verify/', TokenVerifyView.as_view(), name='token_verify'),
path('api/create-user/', views.UserCreate.as_view()),
path('api/resource/', views.ResourceTest.as_view()),
path('api/resource/', views.Resource.as_view()),
path('api/logout/', views.Logout.as_view()),
]
......@@ -24,14 +24,17 @@ class UserCreate(generics.CreateAPIView):
error_message = {'error': err}
raise ValidationError(error_message)
# Hanya untuk test token
class ResourceTest(generics.ListAPIView):
queryset = UserAccount.objects.all()
# Untuk get user
class Resource(generics.ListAPIView):
serializer_class = UserSerializer
permission_classes = [IsAuthenticated]
parser_classes = (CamelCaseJSONParser, CamelCaseFormParser, CamelCaseMultiPartParser, )
renderer_classes = (CamelCaseJSONRenderer, CamelCaseBrowsableAPIRenderer, )
def get_queryset(self):
user = UserAccount.objects.get(username = self.request.user)
return [user]
# Antara pakai logout ini atau langsung di react
class Logout(generics.CreateAPIView):
serializer_class = LogoutSerializer
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment