신은섭(Shin Eun Seop)

add session auth

...@@ -3,6 +3,9 @@ from django.contrib.auth.decorators import login_required ...@@ -3,6 +3,9 @@ from django.contrib.auth.decorators import login_required
3 from rest_framework.views import APIView 3 from rest_framework.views import APIView
4 from rest_framework.response import Response 4 from rest_framework.response import Response
5 from rest_framework import status 5 from rest_framework import status
6 +from rest_framework.authentication import SessionAuthentication, BasicAuthentication
7 +from rest_framework.permissions import IsAuthenticated
8 +
6 from restful import s3_interface 9 from restful import s3_interface
7 10
8 from restful.models import File 11 from restful.models import File
...@@ -12,6 +15,8 @@ class FileList(APIView): ...@@ -12,6 +15,8 @@ class FileList(APIView):
12 """ 15 """
13 List all file, or create a new snippet. 16 List all file, or create a new snippet.
14 """ 17 """
18 + authentication_classes = (SessionAuthentication, BasicAuthentication)
19 + permission_classes = (IsAuthenticated,)
15 20
16 """ 21 """
17 list files or view detail 22 list files or view detail
...@@ -53,6 +58,8 @@ class FileDetail(APIView): ...@@ -53,6 +58,8 @@ class FileDetail(APIView):
53 """ 58 """
54 Download or delete a file instance. 59 Download or delete a file instance.
55 """ 60 """
61 + authentication_classes = (SessionAuthentication, BasicAuthentication)
62 + permission_classes = (IsAuthenticated,)
56 63
57 def get(self, request, path="/", format=None): 64 def get(self, request, path="/", format=None):
58 # download file from s3 65 # download file from s3
......
...@@ -12,6 +12,6 @@ def home(request): ...@@ -12,6 +12,6 @@ def home(request):
12 12
13 @login_required 13 @login_required
14 def file_list(request): 14 def file_list(request):
15 - files = requests.get('http://localhost:8000/restapi/list/') 15 + cookies = {'sessionid' : request.session.session_key}
16 - print(files) 16 + files = requests.get('http://localhost:8000/restapi/list/', cookies=cookies)
17 return render(request, 'website/file_list.html', files.json()) 17 return render(request, 'website/file_list.html', files.json())
......