Showing
8 changed files
with
239 additions
and
248 deletions
1 | +# Generated by Django 3.0.7 on 2020-06-10 17:40 | ||
2 | + | ||
3 | +from django.db import migrations, models | ||
4 | + | ||
5 | + | ||
6 | +class Migration(migrations.Migration): | ||
7 | + | ||
8 | + dependencies = [ | ||
9 | + ('api', '0008_item_file_type'), | ||
10 | + ] | ||
11 | + | ||
12 | + operations = [ | ||
13 | + migrations.RemoveField( | ||
14 | + model_name='user', | ||
15 | + name='id', | ||
16 | + ), | ||
17 | + migrations.AlterField( | ||
18 | + model_name='user', | ||
19 | + name='int_id', | ||
20 | + field=models.AutoField(primary_key=True, serialize=False), | ||
21 | + ), | ||
22 | + ] |
1 | +# Generated by Django 3.0.7 on 2020-06-10 17:42 | ||
2 | + | ||
3 | +from django.db import migrations, models | ||
4 | + | ||
5 | + | ||
6 | +class Migration(migrations.Migration): | ||
7 | + | ||
8 | + dependencies = [ | ||
9 | + ('api', '0009_auto_20200611_0240'), | ||
10 | + ] | ||
11 | + | ||
12 | + operations = [ | ||
13 | + migrations.AlterField( | ||
14 | + model_name='user', | ||
15 | + name='current_size', | ||
16 | + field=models.BigIntegerField(blank=True, default=0), | ||
17 | + ), | ||
18 | + migrations.AlterField( | ||
19 | + model_name='user', | ||
20 | + name='total_size', | ||
21 | + field=models.BigIntegerField(blank=True, default=1099511627776), | ||
22 | + ), | ||
23 | + ] |
... | @@ -17,7 +17,7 @@ class Item(models.Model): | ... | @@ -17,7 +17,7 @@ class Item(models.Model): |
17 | status = models.BooleanField() | 17 | status = models.BooleanField() |
18 | 18 | ||
19 | #file = models.FileField(upload_to = \path) | 19 | #file = models.FileField(upload_to = \path) |
20 | - | 20 | + |
21 | class Meta: | 21 | class Meta: |
22 | ordering = ['item_id'] | 22 | ordering = ['item_id'] |
23 | 23 | ||
... | @@ -33,12 +33,13 @@ class SharedItem(models.Model): | ... | @@ -33,12 +33,13 @@ class SharedItem(models.Model): |
33 | 33 | ||
34 | 34 | ||
35 | class User(models.Model): | 35 | class User(models.Model): |
36 | - int_id = models.IntegerField() | 36 | + int_id = models.AutoField(primary_key=True) |
37 | - user_id = models.CharField(max_length = 50) | 37 | + user_id = models.CharField(max_length=50) |
38 | - name = models.CharField(max_length = 50) | 38 | + name = models.CharField(max_length=50) |
39 | - password = models.CharField(max_length = 20) | 39 | + password = models.CharField(max_length=20) |
40 | - total_size = models.IntegerField() | 40 | + total_size = models.BigIntegerField(blank=True, default=1099511627776) |
41 | - current_size = models.IntegerField() | 41 | + current_size = models.BigIntegerField(blank=True, default=0) |
42 | created_time = models.DateTimeField(auto_now=True) | 42 | created_time = models.DateTimeField(auto_now=True) |
43 | + | ||
43 | class Meta: | 44 | class Meta: |
44 | ordering = ['int_id'] | 45 | ordering = ['int_id'] | ... | ... |
1 | -from django.contrib.auth.models import User, Group | ||
2 | from rest_framework import serializers | 1 | from rest_framework import serializers |
3 | -from api.models import Item, SharedItem | 2 | +from api.models import User |
4 | 3 | ||
5 | 4 | ||
6 | -class UserSerializer(serializers.HyperlinkedModelSerializer): | 5 | +class UserSerializer(serializers.ModelSerializer): |
7 | class Meta: | 6 | class Meta: |
8 | model = User | 7 | model = User |
9 | - fields = ['url', 'username', 'email', 'groups'] | 8 | + fields = '__all__' |
9 | + | ||
10 | + | ||
11 | +class SignUpSerializer(serializers.ModelSerializer): | ||
12 | + password2 = serializers.CharField(style={"input_type": "password"}) | ||
10 | 13 | ||
11 | -class GroupSerializer(serializers.HyperlinkedModelSerializer): | ||
12 | class Meta: | 14 | class Meta: |
13 | - model = Group | 15 | + model = User |
14 | - fields = ['url', 'name'] | 16 | + fields = ['user_id', 'name', 'password', 'password2'] |
15 | 17 | ||
16 | -class ItemSerializer(serializers.ModelSerializer): | 18 | + def create(self, data): |
19 | + user_id = data['user_id'] | ||
20 | + name = data['name'] | ||
21 | + password = self.data['password'] | ||
22 | + password2 = self.data['password2'] | ||
23 | + if user_id and User.objects.filter(user_id=user_id).exclude(name=name).exists(): | ||
24 | + raise serializers.ValidationError({"user_id": "User_id must be unique."}) | ||
25 | + elif password != password2: | ||
26 | + raise serializers.ValidationError({'password': "Passwords must match."}) | ||
27 | + user = User.objects.create( | ||
28 | + user_id=data['user_id'], | ||
29 | + name=data['name'], | ||
30 | + password=data['password'], | ||
31 | + ) | ||
32 | + user.save() | ||
33 | + return user | ||
34 | + | ||
35 | + | ||
36 | +class UserInfoSerializer(serializers.ModelSerializer): | ||
17 | class Meta: | 37 | class Meta: |
18 | - model = Item | 38 | + model = User |
19 | - fields = '__all__' | 39 | + fields = ['user_id', 'name', 'total_size', 'current_size', 'created_time'] |
20 | 40 | ... | ... |
backend/api/utils.py
0 → 100644
1 | +import jwt | ||
2 | +import json | ||
3 | +from rest_framework import status | ||
4 | +from django.http import JsonResponse | ||
5 | +from django.core.exceptions import ObjectDoesNotExist | ||
6 | +from django.conf import settings | ||
7 | +from api.models import User | ||
8 | + | ||
9 | + | ||
10 | +def login_decorator(func): | ||
11 | + def wrapper(self, request, *args, **kwargs): | ||
12 | + if 'Authorization' not in request.headers: | ||
13 | + return JsonResponse({'Error': 'INVALID_LOGIN'}, status=status.HTTP_401_UNAUTHORIZED) | ||
14 | + encode_token = request.headers['Authorization'] | ||
15 | + try: | ||
16 | + payload = jwt.decode(encode_token, settings.SECRET_KEY, algorithm='HS256') | ||
17 | + user = User.objects.get(int_id=payload['int_id']) | ||
18 | + request.user = user | ||
19 | + except jwt.exceptions.DecodeError: | ||
20 | + return JsonResponse({'Error': 'INVALID_TOKEN'}, status=status.HTTP_400) | ||
21 | + except User.DoesNotExist: | ||
22 | + return JsonResponse({'Error': 'UNKNOWN_USER'}, status=status.HTTP_400) | ||
23 | + return func(self, request, *args, **kwargs) | ||
24 | + return wrapper | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | -import mimetypes | 1 | +from api.models import User |
2 | -import json | ||
3 | -import os | ||
4 | -from datetime import datetime | ||
5 | - | ||
6 | -import boto3 | ||
7 | - | ||
8 | -from django.contrib.auth.models import User | ||
9 | -from django.core import serializers | ||
10 | -from django.views.decorators.csrf import csrf_exempt | ||
11 | from rest_framework import viewsets | 2 | from rest_framework import viewsets |
12 | from rest_framework import permissions | 3 | from rest_framework import permissions |
4 | +from rest_framework.permissions import IsAuthenticated | ||
5 | +from rest_framework_jwt.authentication import JSONWebTokenAuthentication | ||
6 | +from rest_framework.decorators import action, permission_classes, authentication_classes | ||
7 | +from rest_framework import status | ||
8 | +from api.serializers import UserSerializer, SignUpSerializer | ||
13 | from rest_framework.response import Response | 9 | from rest_framework.response import Response |
14 | -from rest_framework.decorators import action | 10 | +from django.http import HttpResponse, JsonResponse |
15 | -from rest_framework.permissions import IsAuthenticated, AllowAny | 11 | +import jwt |
12 | +import json | ||
13 | +from datetime import datetime, timedelta | ||
14 | +from .utils import login_decorator | ||
15 | +from django.conf import settings | ||
16 | +from django.views.decorators.csrf import csrf_exempt | ||
16 | 17 | ||
17 | -from api.models import Item, SharedItem | ||
18 | -from api.serializers import UserSerializer,GroupSerializer,ItemSerializer | ||
19 | -from rest_framework import status | ||
20 | -from annoying.functions import get_object_or_None | ||
21 | 18 | ||
22 | class UserViewSet(viewsets.ModelViewSet): | 19 | class UserViewSet(viewsets.ModelViewSet): |
23 | """ | 20 | """ |
24 | API endpoint that allows users to be viewed or edited. | 21 | API endpoint that allows users to be viewed or edited. |
25 | """ | 22 | """ |
26 | - queryset = User.objects.all().order_by('-date_joined') | 23 | + queryset = User.objects.all().order_by('-int_id') |
27 | serializer_class = UserSerializer | 24 | serializer_class = UserSerializer |
28 | permission_classes = [permissions.IsAuthenticated] | 25 | permission_classes = [permissions.IsAuthenticated] |
26 | + authentication_classes = [JSONWebTokenAuthentication] | ||
29 | 27 | ||
28 | + @csrf_exempt | ||
29 | + @action(detail=False, methods=['POST'], permission_classes=[permissions.AllowAny], url_path='signup', url_name='singup') | ||
30 | + def signup(self, request): | ||
31 | + serializer = SignUpSerializer(data=request.data) | ||
32 | + if serializer.is_valid(): | ||
33 | + user = serializer.create(data=request.data) | ||
34 | + return Response({ | ||
35 | + 'message': 'user created', | ||
36 | + 'int_id': user.int_id, | ||
37 | + 'user_id': user.user_id, | ||
38 | + 'name': user.name, | ||
39 | + 'total_size': user.total_size, | ||
40 | + 'current_size': user.current_size, | ||
41 | + 'created_time': user.created_time | ||
42 | + }, | ||
43 | + status=status.HTTP_200_OK, | ||
44 | + ) | ||
45 | + else: | ||
46 | + return Response(serializer.errors, | ||
47 | + status=status.HTTP_400_BAD_REQUEST) | ||
30 | 48 | ||
31 | -class ItemViewSet(viewsets.ViewSet): | 49 | + @csrf_exempt |
32 | - | 50 | + @action(methods=['post'], detail=False, permission_classes=[permissions.AllowAny], |
33 | - queryset = Item.objects.all() | 51 | + url_path='login', url_name='login') |
34 | - serializer_class = ItemSerializer | 52 | + def login(self, request): |
35 | - permission_classes = [permissions.IsAuthenticatedOrReadOnly, permissions.AllowAny, | 53 | + if not request.data: |
36 | - #IsOwnerOrReadOnly | 54 | + return Response({'Error': "Please provide user_id/password"}, status=status.HTTP_400_BAD_REQUEST) |
37 | - ] | 55 | + user_id = request.POST['user_id'] |
38 | - permission_classes_by_action = {'get': [permissions.AllowAny], | 56 | + password = request.POST['password'] |
39 | - 'destroy': [permissions.AllowAny]} | ||
40 | - | ||
41 | - # url: items/search | ||
42 | - @action(methods=['GET'], detail=False, permission_classes=[AllowAny], url_path='search', url_name='search') | ||
43 | - def search(self, request): | ||
44 | - if request.method == 'GET': | ||
45 | - keyword = request.GET.get('keyword', '') | ||
46 | - item_list = Item.objects.filter(name__icontains = keyword) | ||
47 | - | ||
48 | - data = serializers.serialize("json", item_list) | ||
49 | - json_data = json.loads(data) | ||
50 | - res = [] | ||
51 | - for i in json_data: | ||
52 | - t = i['fields'] | ||
53 | - t['id'] = i['pk'] | ||
54 | - res.append(t) | ||
55 | - return Response({'data': {'list' : res}}, status=status.HTTP_200_OK) | ||
56 | - | ||
57 | - # url: items/11/ | ||
58 | - # 마지막 slash도 써주어야함 | ||
59 | - def get(self, request, pk): | ||
60 | - item = Item.objects.filter(item_id=pk) | ||
61 | - data = serializers.serialize("json", item) | ||
62 | - json_data = json.loads(data) | ||
63 | - res = json_data[0]['fields'] | ||
64 | - res['id']=json_data[0]['pk'] | ||
65 | - return Response({'data': res}, status=status.HTTP_200_OK) | ||
66 | - | ||
67 | - # url: items/11/ | ||
68 | - # 마지막 slash도 써주어야함 | ||
69 | - def destroy(self, request, pk): | ||
70 | - if request.method == 'DELETE': | ||
71 | - print(pk) | ||
72 | - item = get_object_or_None(Item, item_id=pk) | ||
73 | - if item != None: | ||
74 | - if item.is_folder == True: # 폴더는 삭제 안되도록 처리 | ||
75 | - return Response({'message': 'This item is folder.'}, status=status.HTTP_200_OK) | ||
76 | - item.is_deleted = True | ||
77 | - item.save() | ||
78 | - # item.delete() 이거 하면 완전 삭제되어버림 is deleted True 면 휴지통에서 리스트 조회할 수 있도록! | ||
79 | - return Response({'message': 'delete complete'},status=status.HTTP_200_OK) | ||
80 | - return Response({'message': 'item is not existed.'}, status=status.HTTP_204_NO_CONTENT) | ||
81 | - | ||
82 | - # url: items/11/move | ||
83 | - # 마지막 slash도 써주어야함 | ||
84 | - @action(methods=['POST'], detail=True, permission_classes=[AllowAny], url_path='move', url_name='move') | ||
85 | - def move(self, request, pk): | ||
86 | - if request.method == 'POST': | ||
87 | - parent_id = request.POST.get('parent', '') | ||
88 | - name = request.POST.get('name','') | ||
89 | - parent = get_object_or_None(Item, item_id=parent_id) | ||
90 | - if parent != None and parent.is_folder == True: | ||
91 | - child = get_object_or_None(Item, item_id=pk) | ||
92 | - if child == None: | ||
93 | - return Response({'message': 'item is not existed.'}, status=status.HTTP_204_NO_CONTENT) | ||
94 | - child.parent = parent_id | ||
95 | - child.save() | ||
96 | - child = Item.objects.filter(item_id = pk) | ||
97 | - child_data = serializers.serialize("json", child) | ||
98 | - json_child = json.loads(child_data) | ||
99 | - res = json_child[0]['fields'] | ||
100 | - res['id'] = pk | ||
101 | - parent = Item.objects.filter(item_id = parent_id) | ||
102 | - parent_data = serializers.serialize("json", parent) | ||
103 | - json_parent = json.loads(parent_data)[0]['fields'] | ||
104 | - res['parentInfo'] = json_parent | ||
105 | - return Response({'data': res}, status=status.HTTP_200_OK) | ||
106 | - if parent == None: | ||
107 | - return Response({'message': 'parent is not existed.'}, status=status.HTTP_200_OK) | ||
108 | - if parent.is_folder == False: | ||
109 | - return Response({'message': 'parent is not folder.'}, status=status.HTTP_200_OK) | ||
110 | - return Response({'message': 'item is not existed.'}, status=status.HTTP_204_NO_CONTENT) | ||
111 | - | ||
112 | - @action(methods=['POST'], detail=True, permission_classes=[AllowAny], url_path='copy', url_name='copy') | ||
113 | - def copy(self, request, pk): | ||
114 | - if request.method == 'POST': | ||
115 | - parent_id = request.POST.get('parent', '') | ||
116 | - parent = get_object_or_None(Item, item_id=parent_id) | ||
117 | - if parent != None and parent.is_folder == True: | ||
118 | - child = get_object_or_None(Item, item_id=pk) | ||
119 | - if child == None: | ||
120 | - return Response({'message': 'item is not existed.'}, status=status.HTTP_204_NO_CONTENT) | ||
121 | - if child.is_folder == True: | ||
122 | - return Response({'message': 'item is folder'}, status=status.HTTP_204_NO_CONTENT) | ||
123 | - copiedName = child.name + "_복사본_" + str(datetime.now().strftime('%Y-%m-%d %H:%M')) | ||
124 | - copiedItem = Item(is_folder = False, name = copiedName, path =child.path, parent = parent_id, user_id= child.user_id, size=child.size, status=child.status) | ||
125 | - copiedItem.save() | ||
126 | - | ||
127 | - copiedItem = Item.objects.filter(name = copiedName) | ||
128 | - copied_data = serializers.serialize("json", copiedItem) | ||
129 | - json_data = json.loads(copied_data) | ||
130 | - res = json_data[0]['fields'] | ||
131 | - res['id'] = json_data[0]['pk'] | ||
132 | - parent = Item.objects.filter(item_id = parent_id) | ||
133 | - parent_data = serializers.serialize("json", parent) | ||
134 | - json_parent = json.loads(parent_data)[0]['fields'] | ||
135 | - res['parentInfo'] = json_parent | ||
136 | - return Response({'data': res}, status=status.HTTP_200_OK) | ||
137 | - if parent == None: | ||
138 | - return Response({'message': 'parent is not existed.'}, status=status.HTTP_200_OK) | ||
139 | - if parent.is_folder == False: | ||
140 | - return Response({'message': 'parent is not folder.'}, status=status.HTTP_200_OK) | ||
141 | - return Response({'message': 'item is not existed.'}, status=status.HTTP_204_NO_CONTENT) | ||
142 | - | ||
143 | - def get_permissions(self): | ||
144 | try: | 57 | try: |
145 | - # return permission_classes depending on `action` | 58 | + user = User.objects.get(user_id=user_id, password=password) |
146 | - return [permission() for permission in self.permission_classes_by_action[self.action]] | 59 | + except User.DoesNotExist: |
147 | - except KeyError: | 60 | + return Response({'Error': "Invalid user_id/password"}, status=status.HTTP_400_BAD_REQUEST) |
148 | - # action is not set return default permission_classes | 61 | + if user: |
149 | - return [permission() for permission in self.permission_classes] | 62 | + payload1 = { |
150 | - | 63 | + 'int_id': user.int_id, |
64 | + 'user_id': user.user_id, | ||
65 | + 'exp': datetime.utcnow() + timedelta(seconds=300) | ||
66 | + } | ||
67 | + payload2 = { | ||
68 | + 'int_id': user.int_id, | ||
69 | + 'user_id': user.user_id, | ||
70 | + 'exp': datetime.utcnow() + timedelta(days=5) | ||
71 | + } | ||
72 | + access = jwt.encode(payload1, settings.SECRET_KEY, algorithm='HS256') | ||
73 | + access = access.decode('utf-8') | ||
74 | + refresh = jwt.encode(payload2, settings.SECRET_KEY, algorithm='HS256') | ||
75 | + refresh = refresh.decode('utf-8') | ||
76 | + exp = jwt.decode(access, settings.SECRET_KEY, algorithm='HS256')['exp'] | ||
77 | + token = {'access': access, | ||
78 | + 'refresh': refresh, | ||
79 | + 'exp': exp} | ||
80 | + return JsonResponse( | ||
81 | + token, | ||
82 | + status=status.HTTP_200_OK, | ||
83 | + ) | ||
84 | + else: | ||
85 | + return JsonResponse( | ||
86 | + {'Error': "Invalid credentials"}, | ||
87 | + status=status.HTTP_400_BAD_REQUEST, | ||
88 | + ) | ||
89 | + return JsonResponse(status=status.HTTP_405_METHOD_NOT_ALLOWED) | ||
151 | 90 | ||
152 | -class SharedItemViewSet(viewsets.ModelViewSet): | ||
153 | - | ||
154 | - queryset = SharedItem.objects.all() | ||
155 | - # serializer_class = SharedItemSerializer | ||
156 | - permission_classes = [permissions.IsAuthenticatedOrReadOnly, permissions.AllowAny, | ||
157 | - # IsOwnerOrReadOnly | ||
158 | - ] | ||
159 | - # url: http://localhost:8000/items/1/share/ | ||
160 | - # 마지막 slash도 써주어야함 | ||
161 | @csrf_exempt | 91 | @csrf_exempt |
162 | - @action(methods=['POST'], detail=True, permission_classes=[AllowAny], url_path='share', url_name='share') | 92 | + @login_decorator |
163 | - def share(self, request, pk): | 93 | + @action(methods=['POST'], detail=False, url_path='renew', url_name='renew') |
164 | - if request.method == 'POST': | 94 | + def renew(self, request): |
165 | - password = request.POST.get('password', '') | 95 | + user = request.user |
166 | - expires = request.POST.get('expires', '') | 96 | + payload1 = { |
167 | - | 97 | + 'int_id': user.int_id, |
168 | - sharedfile = get_object_or_None(SharedItem, item_id=pk) | 98 | + 'user_id': user.user_id, |
169 | - if sharedfile != None: | 99 | + 'exp': datetime.utcnow() + timedelta(seconds=300) |
170 | - # 서버는 정상이나 이미 공유객체로 등록된 파일임 | 100 | + } |
171 | - return Response({'message': 'This file is already shared'}, status=status.HTTP_200_OK) | 101 | + payload2 = { |
172 | - sharedfile = SharedItem(item_id =pk, password=password, expires = expires) | 102 | + 'int_id': user.int_id, |
173 | - sharedfile.save() | 103 | + 'user_id': user.user_id, |
174 | - sharedfile = SharedItem.objects.get(item_id = pk) | 104 | + 'exp': datetime.utcnow() + timedelta(days=5) |
175 | - | 105 | + } |
176 | - # sf = serializers.serialize("json", sharedfile) | 106 | + access = jwt.encode(payload1, settings.SECRET_KEY, algorithm='HS256') |
177 | - item = Item.objects.filter(item_id = pk) | 107 | + refresh = jwt.encode(payload2, settings.SECRET_KEY, algorithm='HS256') |
178 | - item_json = serializers.serialize("json", item) | 108 | + exp = jwt.decode(access, settings.SECRET_KEY, algorithm='HS256')['exp'] |
109 | + token = {'access': access, | ||
110 | + 'refresh': refresh, | ||
111 | + 'exp': exp} | ||
112 | + return JsonResponse( | ||
113 | + token, | ||
114 | + status=status.HTTP_200_OK, | ||
115 | + ) | ||
179 | 116 | ||
180 | - json_data = json.loads(item_json) | ||
181 | - print(json_data) | ||
182 | - res = json_data[0]['fields'] | ||
183 | - res['id'] = json_data[0]['pk'] | ||
184 | - return Response({"shared": sharedfile.created_time , 'data': res}, status=status.HTTP_200_OK) | ||
185 | - | ||
186 | -item = ItemViewSet.as_view({ | ||
187 | - 'delete': 'destroy', | ||
188 | -}) | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
117 | + @csrf_exempt | ||
118 | + @login_decorator | ||
119 | + @action(methods=['GET'], detail=True, permission_classes=[permissions.IsAuthenticated], | ||
120 | + url_path='info', url_name='info') | ||
121 | + def info(self, request, pk): | ||
122 | + if request.method == 'GET': | ||
123 | + user = User.objects.get(id=pk) | ||
124 | + data = { | ||
125 | + 'int_id': user.int_id, | ||
126 | + 'user_id': user.user_id, | ||
127 | + 'name': user.name, | ||
128 | + 'total_size': user.total_size, | ||
129 | + 'current_size': user.current_size, | ||
130 | + 'created_time': user.created_time | ||
131 | + } | ||
132 | + return HttpResponse( | ||
133 | + data, | ||
134 | + status=status.HTTP_200_OK, | ||
135 | + content_type="application/json") | ||
136 | + return HttpResponse( | ||
137 | + {'Error': 'The Method is not allowed.'}, | ||
138 | + status=status.HTTP_405_METHOD_NOT_ALLOWED, | ||
139 | + content_type="application/json") | ... | ... |
1 | """ | 1 | """ |
2 | Django settings for khudrive project. | 2 | Django settings for khudrive project. |
3 | - | ||
4 | Generated by 'django-admin startproject' using Django 3.0.7. | 3 | Generated by 'django-admin startproject' using Django 3.0.7. |
5 | - | ||
6 | For more information on this file, see | 4 | For more information on this file, see |
7 | https://docs.djangoproject.com/en/3.0/topics/settings/ | 5 | https://docs.djangoproject.com/en/3.0/topics/settings/ |
8 | - | ||
9 | For the full list of settings and their values, see | 6 | For the full list of settings and their values, see |
10 | https://docs.djangoproject.com/en/3.0/ref/settings/ | 7 | https://docs.djangoproject.com/en/3.0/ref/settings/ |
11 | """ | 8 | """ |
12 | - | ||
13 | import os | 9 | import os |
14 | - | ||
15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) | 10 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) |
16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 11 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
17 | - | ||
18 | - | ||
19 | # Quick-start development settings - unsuitable for production | 12 | # Quick-start development settings - unsuitable for production |
20 | # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ | 13 | # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ |
21 | - | ||
22 | # SECURITY WARNING: keep the secret key used in production secret! | 14 | # SECURITY WARNING: keep the secret key used in production secret! |
23 | SECRET_KEY = ')i0_(*4t7k3=rcqp*_i0u((9zbk8q(2(3tk(%$woji-e-37=o*' | 15 | SECRET_KEY = ')i0_(*4t7k3=rcqp*_i0u((9zbk8q(2(3tk(%$woji-e-37=o*' |
24 | - | ||
25 | # SECURITY WARNING: don't run with debug turned on in production! | 16 | # SECURITY WARNING: don't run with debug turned on in production! |
26 | DEBUG = True | 17 | DEBUG = True |
27 | - | ||
28 | ALLOWED_HOSTS = [] | 18 | ALLOWED_HOSTS = [] |
29 | - | ||
30 | - | ||
31 | # Application definition | 19 | # Application definition |
32 | - | ||
33 | INSTALLED_APPS = [ | 20 | INSTALLED_APPS = [ |
34 | 'django.contrib.admin', | 21 | 'django.contrib.admin', |
35 | 'django.contrib.auth', | 22 | 'django.contrib.auth', |
... | @@ -40,7 +27,6 @@ INSTALLED_APPS = [ | ... | @@ -40,7 +27,6 @@ INSTALLED_APPS = [ |
40 | 'rest_framework', | 27 | 'rest_framework', |
41 | 'api.apps.ApiConfig', | 28 | 'api.apps.ApiConfig', |
42 | ] | 29 | ] |
43 | - | ||
44 | MIDDLEWARE = [ | 30 | MIDDLEWARE = [ |
45 | 'django.middleware.security.SecurityMiddleware', | 31 | 'django.middleware.security.SecurityMiddleware', |
46 | 'django.contrib.sessions.middleware.SessionMiddleware', | 32 | 'django.contrib.sessions.middleware.SessionMiddleware', |
... | @@ -50,9 +36,7 @@ MIDDLEWARE = [ | ... | @@ -50,9 +36,7 @@ MIDDLEWARE = [ |
50 | 'django.contrib.messages.middleware.MessageMiddleware', | 36 | 'django.contrib.messages.middleware.MessageMiddleware', |
51 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', | 37 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', |
52 | ] | 38 | ] |
53 | - | ||
54 | ROOT_URLCONF = 'khudrive.urls' | 39 | ROOT_URLCONF = 'khudrive.urls' |
55 | - | ||
56 | TEMPLATES = [ | 40 | TEMPLATES = [ |
57 | { | 41 | { |
58 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', | 42 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', |
... | @@ -68,10 +52,7 @@ TEMPLATES = [ | ... | @@ -68,10 +52,7 @@ TEMPLATES = [ |
68 | }, | 52 | }, |
69 | }, | 53 | }, |
70 | ] | 54 | ] |
71 | - | ||
72 | WSGI_APPLICATION = 'khudrive.wsgi.application' | 55 | WSGI_APPLICATION = 'khudrive.wsgi.application' |
73 | - | ||
74 | - | ||
75 | # Database | 56 | # Database |
76 | # https://docs.djangoproject.com/en/3.0/ref/settings/#databases | 57 | # https://docs.djangoproject.com/en/3.0/ref/settings/#databases |
77 | DATABASES = { | 58 | DATABASES = { |
... | @@ -82,17 +63,14 @@ DATABASES = { | ... | @@ -82,17 +63,14 @@ DATABASES = { |
82 | 'default': { | 63 | 'default': { |
83 | 'ENGINE': 'django.db.backends.postgresql', | 64 | 'ENGINE': 'django.db.backends.postgresql', |
84 | 'NAME': 'khuDrive', | 65 | 'NAME': 'khuDrive', |
85 | - 'USER': 'jooheekwon', | 66 | + 'USER': 'hjy', |
86 | - 'PASSWORD': '', | 67 | + 'PASSWORD': '2521', |
87 | 'HOST': 'localhost', | 68 | 'HOST': 'localhost', |
88 | - 'PORT': '', | 69 | + 'PORT': '5432', |
89 | } | 70 | } |
90 | } | 71 | } |
91 | - | ||
92 | - | ||
93 | # Password validation | 72 | # Password validation |
94 | # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators | 73 | # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators |
95 | - | ||
96 | AUTH_PASSWORD_VALIDATORS = [ | 74 | AUTH_PASSWORD_VALIDATORS = [ |
97 | { | 75 | { |
98 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', | 76 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', |
... | @@ -107,23 +85,13 @@ AUTH_PASSWORD_VALIDATORS = [ | ... | @@ -107,23 +85,13 @@ AUTH_PASSWORD_VALIDATORS = [ |
107 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', | 85 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', |
108 | }, | 86 | }, |
109 | ] | 87 | ] |
110 | - | ||
111 | - | ||
112 | # Internationalization | 88 | # Internationalization |
113 | # https://docs.djangoproject.com/en/3.0/topics/i18n/ | 89 | # https://docs.djangoproject.com/en/3.0/topics/i18n/ |
114 | - | ||
115 | LANGUAGE_CODE = 'en-us' | 90 | LANGUAGE_CODE = 'en-us' |
116 | - | ||
117 | TIME_ZONE = 'UTC' | 91 | TIME_ZONE = 'UTC' |
118 | - | ||
119 | USE_I18N = True | 92 | USE_I18N = True |
120 | - | ||
121 | USE_L10N = True | 93 | USE_L10N = True |
122 | - | ||
123 | USE_TZ = True | 94 | USE_TZ = True |
124 | - | ||
125 | - | ||
126 | # Static files (CSS, JavaScript, Images) | 95 | # Static files (CSS, JavaScript, Images) |
127 | # https://docs.djangoproject.com/en/3.0/howto/static-files/ | 96 | # https://docs.djangoproject.com/en/3.0/howto/static-files/ |
128 | - | 97 | +STATIC_URL = '/static/' |
129 | -STATIC_URL = '/static/' | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | -"""khudrive URL Configuration | ||
2 | - | ||
3 | -The `urlpatterns` list routes URLs to views. For more information please see: | ||
4 | - https://docs.djangoproject.com/en/3.0/topics/http/urls/ | ||
5 | -Examples: | ||
6 | -Function views | ||
7 | - 1. Add an import: from my_app import views | ||
8 | - 2. Add a URL to urlpatterns: path('', views.home, name='home') | ||
9 | -Class-based views | ||
10 | - 1. Add an import: from other_app.views import Home | ||
11 | - 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') | ||
12 | -Including another URLconf | ||
13 | - 1. Import the include() function: from django.urls import include, path | ||
14 | - 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) | ||
15 | -""" | ||
16 | from django.urls import include, path | 1 | from django.urls import include, path |
17 | from rest_framework import routers | 2 | from rest_framework import routers |
18 | from django.contrib import admin | 3 | from django.contrib import admin |
19 | from api import views | 4 | from api import views |
20 | from django.conf.urls import url | 5 | from django.conf.urls import url |
21 | - | ||
22 | router = routers.DefaultRouter() | 6 | router = routers.DefaultRouter() |
23 | router.register(r'users', views.UserViewSet) | 7 | router.register(r'users', views.UserViewSet) |
24 | -router.register(r'items', views.ItemViewSet) | ||
25 | -router.register(r'items', views.SharedItemViewSet) | ||
26 | 8 | ||
27 | # Wire up our API using automatic URL routing. | 9 | # Wire up our API using automatic URL routing. |
28 | # Additionally, we include login URLs for the browsable API. | 10 | # Additionally, we include login URLs for the browsable API. |
29 | urlpatterns = [ | 11 | urlpatterns = [ |
30 | path('admin/', admin.site.urls), | 12 | path('admin/', admin.site.urls), |
31 | path('', include(router.urls)), | 13 | path('', include(router.urls)), |
32 | - url(r'^search/$', views.ItemViewSet.search, name='search'), | 14 | + url(r'^signup/$', views.UserViewSet.signup, name='signup'), |
33 | - url(r'^<int:pk>/share/$', views.SharedItemViewSet.share, name='share'), | 15 | + url(r'^login/$', views.UserViewSet.login, name='login'), |
34 | - url(r'^<int:pk>/move/$', views.ItemViewSet.move, name='move'), | 16 | + url(r'^renew/$', views.UserViewSet.renew, name='renew'), |
35 | - url(r'^<int:pk>/copy/$', views.ItemViewSet.copy, name='copy'), | 17 | + url(r'^<int:pk>/info/$', views.UserViewSet.info, name='info'), |
36 | - | 18 | + path('api-auth/', include('rest_framework.urls', namespace='rest_framework')), |
37 | -] | 19 | +] |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment