Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-CloudComputing
/
C_Team_KhuDrive
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
권주희
2020-06-12 00:07:24 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5f09800c78a18566d0aecae7be9b0641ba4f01eb
5f09800c
1 parent
928be0be
add signup, login api
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
96 additions
and
164 deletions
backend/api/migrations/0001_initial.py
backend/api/migrations/0002_auto_20200605_1851.py
backend/api/migrations/0003_auto_20200606_0817.py
backend/api/migrations/0004_auto_20200606_0824.py
backend/api/migrations/0005_auto_20200610_1150.py
backend/api/migrations/0006_auto_20200610_1209.py
backend/api/migrations/0007_auto_20200610_1217.py
backend/api/migrations/0008_item_file_type.py
backend/api/models.py
backend/api/views.py
backend/khudrive/urls.py
backend/api/migrations/0001_initial.py
View file @
5f09800
# Generated by Django 3.0.
7 on 2020-06-04 19:52
# Generated by Django 3.0.
6 on 2020-06-11 14:54
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
...
...
@@ -13,12 +12,33 @@ class Migration(migrations.Migration):
operations
=
[
migrations
.
CreateModel
(
name
=
'Item'
,
fields
=
[
(
'item_id'
,
models
.
AutoField
(
primary_key
=
True
,
serialize
=
False
)),
(
'is_folder'
,
models
.
BooleanField
(
default
=
False
)),
(
'name'
,
models
.
CharField
(
max_length
=
50
)),
(
'file_type'
,
models
.
CharField
(
max_length
=
100
,
null
=
True
)),
(
'path'
,
models
.
TextField
()),
(
'parent'
,
models
.
IntegerField
()),
(
'user_id'
,
models
.
IntegerField
()),
(
'size'
,
models
.
IntegerField
()),
(
'is_deleted'
,
models
.
BooleanField
(
default
=
False
)),
(
'created_time'
,
models
.
DateTimeField
(
auto_now
=
True
)),
(
'updated_time'
,
models
.
DateTimeField
(
null
=
True
)),
(
'status'
,
models
.
BooleanField
()),
],
options
=
{
'ordering'
:
[
'item_id'
],
},
),
migrations
.
CreateModel
(
name
=
'SharedItem'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'item_id'
,
models
.
IntegerField
()),
(
'
valid'
,
models
.
DateTimeField
()),
(
'
expires'
,
models
.
DateTimeField
()),
(
'password'
,
models
.
CharField
(
max_length
=
20
)),
(
'created_time'
,
models
.
DateTimeField
(
auto_now
=
True
)),
],
options
=
{
'ordering'
:
[
'item_id'
],
...
...
@@ -27,35 +47,16 @@ class Migration(migrations.Migration):
migrations
.
CreateModel
(
name
=
'User'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'int_id'
,
models
.
IntegerField
()),
(
'int_id'
,
models
.
AutoField
(
primary_key
=
True
,
serialize
=
False
)),
(
'user_id'
,
models
.
CharField
(
max_length
=
50
)),
(
'name'
,
models
.
CharField
(
max_length
=
50
)),
(
'password'
,
models
.
CharField
(
max_length
=
20
)),
(
'total_size'
,
models
.
IntegerField
()),
(
'current_size'
,
models
.
IntegerField
()),
(
'created_time'
,
models
.
DateTimeField
(
auto_now
=
True
)),
],
options
=
{
'ordering'
:
[
'int_id'
],
},
),
migrations
.
CreateModel
(
name
=
'Item'
,
fields
=
[
(
'item_id'
,
models
.
IntegerField
(
primary_key
=
True
,
serialize
=
False
)),
(
'is_folder'
,
models
.
BooleanField
(
default
=
False
)),
(
'name'
,
models
.
CharField
(
max_length
=
50
)),
(
'path'
,
models
.
TextField
()),
(
'user_id'
,
models
.
IntegerField
()),
(
'size'
,
models
.
IntegerField
()),
(
'is_deleted'
,
models
.
BooleanField
(
default
=
False
)),
(
'created_time'
,
models
.
DateTimeField
()),
(
'updated_time'
,
models
.
DateTimeField
()),
(
'status'
,
models
.
BooleanField
()),
(
'parent'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'api.Item'
)),
],
options
=
{
'ordering'
:
[
'item_id'
],
},
),
]
...
...
backend/api/migrations/0002_auto_20200605_1851.py
deleted
100644 → 0
View file @
928be0b
# Generated by Django 3.0.7 on 2020-06-05 09:51
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'api'
,
'0001_initial'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'item'
,
name
=
'parent'
,
field
=
models
.
IntegerField
(),
),
]
backend/api/migrations/0003_auto_20200606_0817.py
deleted
100644 → 0
View file @
928be0b
# Generated by Django 3.0.6 on 2020-06-06 08:17
from
django.db
import
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'api'
,
'0002_auto_20200605_1851'
),
]
operations
=
[
migrations
.
RenameField
(
model_name
=
'shareditem'
,
old_name
=
'valid'
,
new_name
=
'expires'
,
),
]
backend/api/migrations/0004_auto_20200606_0824.py
deleted
100644 → 0
View file @
928be0b
# Generated by Django 3.0.6 on 2020-06-06 08:24
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'api'
,
'0003_auto_20200606_0817'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'shareditem'
,
name
=
'created_time'
,
field
=
models
.
DateTimeField
(
auto_now
=
True
),
),
migrations
.
AddField
(
model_name
=
'user'
,
name
=
'created_time'
,
field
=
models
.
DateTimeField
(
auto_now
=
True
),
),
migrations
.
AlterField
(
model_name
=
'item'
,
name
=
'created_time'
,
field
=
models
.
DateTimeField
(
auto_now
=
True
),
),
]
backend/api/migrations/0005_auto_20200610_1150.py
deleted
100644 → 0
View file @
928be0b
# Generated by Django 3.0.6 on 2020-06-10 11:50
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'api'
,
'0004_auto_20200606_0824'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'item'
,
name
=
'item_id'
,
field
=
models
.
IntegerField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
),
),
]
backend/api/migrations/0006_auto_20200610_1209.py
deleted
100644 → 0
View file @
928be0b
# Generated by Django 3.0.6 on 2020-06-10 12:09
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'api'
,
'0005_auto_20200610_1150'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'item'
,
name
=
'item_id'
,
field
=
models
.
AutoField
(
primary_key
=
True
,
serialize
=
False
),
),
]
backend/api/migrations/0007_auto_20200610_1217.py
deleted
100644 → 0
View file @
928be0b
# Generated by Django 3.0.6 on 2020-06-10 12:17
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'api'
,
'0006_auto_20200610_1209'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'item'
,
name
=
'updated_time'
,
field
=
models
.
DateTimeField
(
null
=
True
),
),
]
backend/api/migrations/0008_item_file_type.py
deleted
100644 → 0
View file @
928be0b
# Generated by Django 3.0.6 on 2020-06-10 13:29
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'api'
,
'0007_auto_20200610_1217'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'item'
,
name
=
'file_type'
,
field
=
models
.
CharField
(
max_length
=
100
,
null
=
True
),
),
]
backend/api/models.py
View file @
5f09800
...
...
@@ -33,7 +33,7 @@ class SharedItem(models.Model):
class
User
(
models
.
Model
):
int_id
=
models
.
IntegerField
(
)
int_id
=
models
.
AutoField
(
primary_key
=
True
)
user_id
=
models
.
CharField
(
max_length
=
50
)
name
=
models
.
CharField
(
max_length
=
50
)
password
=
models
.
CharField
(
max_length
=
20
)
...
...
backend/api/views.py
View file @
5f09800
import
mimetypes
import
json
import
os
from
datetime
import
datetime
from
datetime
import
datetime
,
timedelta
import
boto3
from
django.contrib.auth.models
import
User
from
django.core
import
serializers
from
django.views.decorators.csrf
import
csrf_exempt
from
rest_framework
import
viewsets
...
...
@@ -14,10 +13,13 @@ from rest_framework.response import Response
from
rest_framework.decorators
import
action
from
rest_framework.permissions
import
IsAuthenticated
,
AllowAny
from
api.models
import
Item
,
SharedItem
from
api.models
import
Item
,
SharedItem
,
User
from
api.serializers
import
UserSerializer
,
GroupSerializer
,
ItemSerializer
from
rest_framework
import
status
from
annoying.functions
import
get_object_or_None
from
django.conf
import
settings
import
jwt
from
django.http
import
HttpResponse
,
JsonResponse
class
UserViewSet
(
viewsets
.
ModelViewSet
):
"""
...
...
@@ -27,6 +29,70 @@ class UserViewSet(viewsets.ModelViewSet):
serializer_class
=
UserSerializer
permission_classes
=
[
permissions
.
IsAuthenticated
]
@csrf_exempt
@action
(
detail
=
False
,
methods
=
[
'POST'
],
permission_classes
=
[
permissions
.
AllowAny
],
url_path
=
'signup'
,
url_name
=
'singup'
)
def
signup
(
self
,
request
):
user_id
=
request
.
POST
.
get
(
'user_id'
,
''
)
name
=
request
.
POST
.
get
(
'name'
,
''
)
password
=
request
.
POST
.
get
(
'password'
,
''
)
user
=
get_object_or_None
(
User
,
user_id
=
user_id
)
if
user
==
None
:
user
=
User
(
user_id
=
user_id
,
name
=
name
,
password
=
password
,
total_size
=
100000
,
current_size
=
0
)
user
.
save
()
return
Response
({
'message'
:
'user created'
,
'int_id'
:
user
.
int_id
,
'user_id'
:
user
.
user_id
,
'name'
:
user
.
name
,
'total_size'
:
user
.
total_size
,
'current_size'
:
user
.
current_size
,
'created_time'
:
user
.
created_time
},
status
=
status
.
HTTP_200_OK
,
)
else
:
return
Response
({
'message'
:
'user is already exist.'
},
status
=
status
.
HTTP_204_NO_CONTENT
)
@csrf_exempt
@action
(
methods
=
[
'post'
],
detail
=
False
,
permission_classes
=
[
permissions
.
AllowAny
],
url_path
=
'login'
,
url_name
=
'login'
)
def
login
(
self
,
request
):
if
not
request
.
data
:
return
Response
({
'Error'
:
"Please provide user_id/password"
},
status
=
status
.
HTTP_400_BAD_REQUEST
)
user_id
=
request
.
POST
[
'user_id'
]
password
=
request
.
POST
[
'password'
]
try
:
user
=
User
.
objects
.
get
(
user_id
=
user_id
,
password
=
password
)
except
User
.
DoesNotExist
:
return
Response
({
'Error'
:
"Invalid user_id/password"
},
status
=
status
.
HTTP_400_BAD_REQUEST
)
if
user
:
payload1
=
{
'int_id'
:
user
.
int_id
,
'user_id'
:
user
.
user_id
,
'exp'
:
datetime
.
utcnow
()
+
timedelta
(
seconds
=
300
)
}
payload2
=
{
'int_id'
:
user
.
int_id
,
'user_id'
:
user
.
user_id
,
'exp'
:
datetime
.
utcnow
()
+
timedelta
(
days
=
5
)
}
access
=
jwt
.
encode
(
payload1
,
settings
.
SECRET_KEY
,
algorithm
=
'HS256'
)
.
decode
(
'utf-8'
)
refresh
=
jwt
.
encode
(
payload2
,
settings
.
SECRET_KEY
,
algorithm
=
'HS256'
)
.
decode
(
'utf-8'
)
exp
=
jwt
.
decode
(
access
,
settings
.
SECRET_KEY
,
algorithm
=
'HS256'
)[
'exp'
]
token
=
{
'access'
:
access
,
'refresh'
:
refresh
,
'exp'
:
exp
}
return
JsonResponse
(
token
,
status
=
status
.
HTTP_200_OK
,
)
else
:
return
JsonResponse
(
{
'Error'
:
"Invalid credentials"
},
status
=
status
.
HTTP_400_BAD_REQUEST
,
)
return
JsonResponse
(
status
=
status
.
HTTP_405_METHOD_NOT_ALLOWED
)
class
ItemViewSet
(
viewsets
.
ViewSet
):
...
...
backend/khudrive/urls.py
View file @
5f09800
...
...
@@ -34,5 +34,6 @@ urlpatterns = [
url
(
r'^<int:pk>/move/$'
,
views
.
ItemViewSet
.
move
,
name
=
'move'
),
url
(
r'^<int:pk>/copy/$'
,
views
.
ItemViewSet
.
copy
,
name
=
'copy'
),
url
(
r'^<int:pk>/children/$'
,
views
.
ItemViewSet
.
children
,
name
=
'copy'
),
url
(
r'^signup/$'
,
views
.
UserViewSet
.
signup
,
name
=
'signup'
),
]
...
...
Please
register
or
login
to post a comment