Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions OSDS/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,14 @@ def get_secret(setting, secrets=secrets):
"http://localhost",
"http://127.0.0.1"
]

CSRF_TRUSTED_ORIGINS = ['https://*.cloudtype.app']
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_BROWSER_XSS_FILTER = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
CSRF_TRUSTED_ORIGINS = [
'https://*.cloudtype.app',
'https://*.osds.kro.kr',
"http://*.osds.kro.kr",
]
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
# OSDS-server
# OSDS-server

<img src="./static/img/morakmorak.png" width="300" height="300" />

<br/>

# 👨‍👩‍👧‍👦 Participants 👨‍👩‍👧‍👦
| name | 역할 |
|-------|----------|
| [unanchoi](https://github.com/unanchoi)| Develop |
| [na-yk](https://github.com/na-yk)| Leader, Develop |
| [jinu-kim](https://github.com/jinu-u-kim) | Develop |
| [hi-there-insahae](https://github.com/hi-there-insahae)| Develop |


## 🖥 Implementation

##### 0. Virtual Environment
```python
python -m venv venv
source venv/bin/activate
```

##### 1. Run Server

``` pytho
glt clone https://github.com/NodabFamily/OSDS-server.git

python manage.py migrate

python manage.py runserver
```

## 🗒 Commit Convention
| 제목 | 내용 |
|-------|----------|
| feat | 기능 추가|
| fix | 버그 수정|
| refactor | 기능 개선 및 코드 좋은 방향으로 개선 |
| docs | 문서 관리|
| style | 코드 스타일 변경, 코드 깔끔하게 관리 |
| chore | 기본 세팅 및 settings.py 관련, 패키지 관리 |
Empty file removed accounts/migrations/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

urlpatterns = [
path("users", create_user, name="create_user"),
path("users/<int:id>", read_edit_delete_user, name ="read_edit_delete_user"),
path("users/<int:user_id>", read_edit_delete_user, name ="read_edit_delete_user"),
path("users/login",login_view, name ="login"),
path("users/logout", logout_view, name ="logout"),
]
233 changes: 120 additions & 113 deletions accounts/views.py
Original file line number Diff line number Diff line change
@@ -1,140 +1,152 @@
import json
from django.http import JsonResponse, HttpResponse
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.contrib.auth import authenticate, login, logout, get_user_model
from django.views.decorators.http import require_http_methods
from django.http import JsonResponse
from django.contrib.auth.hashers import make_password
# Create your views here.


User = get_user_model()


@require_http_methods(['POST'])
def create_user(request):
body = json.loads(request.body.decode('utf-8'))
new_user = User.objects.create(
username = body["username"],
password = body["password"],
name = body["name"],
birth = body["birth"],
bio = body["bio"],
is_participant = body["is_participant"],
avatar = body["avatar"],
nickname = body["nickname"]
)
new_user = User.objects.create(
username=body["username"],
password=body["password"],
name=body["name"],
birth=body["birth"],
bio=body["bio"],
is_participant=body["is_participant"],
avatar=body["avatar"],
nickname=body["nickname"]
)
new_user.password = make_password(body["password"])
new_user.save()

new_user_json={
"id" : new_user.id,
"username" : new_user.username,
"name" : new_user.name,
"birth" : new_user.birth,
"bio" : new_user.bio,
"avatar" : new_user.avatar,
"nickname" : new_user.nickname,
"is_participant" : new_user.is_participant
}
new_user_data = {
"id": new_user.id,
"username": new_user.username,
"name": new_user.name,
"birth": new_user.birth,
"bio": new_user.bio,
"avatar": new_user.avatar,
"nickname": new_user.nickname,
"is_participant": new_user.is_participant
}

json_res = json.dumps({
'success': True,
'message': '생성 성공!',
'data': new_user_data
}, ensure_ascii=False)



json_res=json.dumps(
{
'status': 200,
'success': True,
'message': '생성 성공!',
'data': new_user_json
},
ensure_ascii=False
)
return HttpResponse(
json_res,
content_type=u"application/json; charset=utf-8",
status=200
)
json_res,
content_type=u"application/json; charset=utf-8",
status=200
)


@require_http_methods(['POST'])
def login_view(request):
print("request.user : ", request.user)
print("request.POST : ", request.POST.get("username"))
print("request.body : ", request.body)
data = json.loads(request.body.decode("utf-8"))
print("data : ", data)

username = data['username']
password = data['password']

print(username)
print(password)
user = authenticate(request, username=username , password = password)
user = authenticate(request, username=username, password=password)

if user is not None:
login(request, user)
user_data = {
"id" : user.id,
"username" : user.username,
"name" : user.name,
"birth": user.birth,
"bio":user.bio,
"nickname":user.nickname,
"is_participant":user.is_participant
}
return JsonResponse({"success": True, "message" : "로그인 성공", "data" : user_data}, status = 200)
else:
return JsonResponse({"success": False, "message": "로그인 실패"}, status = 403)

"id": user.id,
"username": user.username,
"name": user.name,
"birth": user.birth,
"bio": user.bio,
"avatar": user.avatar,
"nickname": user.nickname,
"is_participant": user.is_participant
}

json_res = json.dumps({
"success": True,
"message": "로그인 성공",
"data": user_data
}, ensure_ascii=False)

return HttpResponse(
json_res,
content_type=u"application/json; charset=utf-8",
status=200
)

else:
json_res = json.dumps({
"success": False,
"message": "로그인 실패"
})

return HttpResponse(
json_res,
content_type=u"application/json; charset=utf-8",
status=403
)


@require_http_methods(['POST'])
def logout_view(request):
logout(request)

return JsonResponse({
json_res = json.dumps({
"success": True,
"message": "로그아웃 성공"},
status = 200)
"message": "로그아웃 성공",
"data": None
}, ensure_ascii=False)

return HttpResponse(
json_res,
content_type=u"application/json; charset=utf-8",
status=200
)


@require_http_methods(['GET','DELETE','PUT'])
def read_edit_delete_user(request,id):
@require_http_methods(['GET', 'DELETE', 'PUT'])
def read_edit_delete_user(request, user_id):
if request.method == "GET":
user_detail = get_object_or_404(User, pk =id)
user_detail_json={
"id" : user_detail.id,
"username" : user_detail.username,
"name" : user_detail.name,
"birth" : user_detail.birth,
"bio" : user_detail.bio,
"avatar" : user_detail.avatar,
"nickname" : user_detail.nickname,
"is_participant" : user_detail.is_participant
user_detail = get_object_or_404(User, pk=user_id)
user_detail_json = {
"id": user_detail.id,
"username": user_detail.username,
"name": user_detail.name,
"birth": user_detail.birth,
"bio": user_detail.bio,
"avatar": user_detail.avatar,
"nickname": user_detail.nickname,
"is_participant": user_detail.is_participant
}
json_res = json.dumps(
{
"status": 200,
"success": True,
"message": "조희 성공!",
"data": user_detail_json
},
ensure_ascii=False
)

json_res = json.dumps({
"success": True,
"message": "조희 성공!",
"data": user_detail_json
}, ensure_ascii=False)

return HttpResponse(
json_res,
content_type=u"application/json; charset=utf-8",
status=200
)

elif request.method == "DELETE":
delete_user = get_object_or_404(User, pk=id)
delete_user = get_object_or_404(User, pk=user_id)
delete_user.delete()
json_res = json.dumps(
{
"status": 200,
"success": True,
"message": "삭제 성공",
"data": None
},
ensure_ascii=False
)

json_res = json.dumps({
"success": True,
"message": "삭제 성공",
"data": None
}, ensure_ascii=False)

return HttpResponse(
json_res,
Expand All @@ -145,7 +157,7 @@ def read_edit_delete_user(request,id):
elif request.method == "PUT":
body = json.loads(request.body.decode('utf-8'))

update_user = get_object_or_404(User, pk =id)
update_user = get_object_or_404(User, pk=user_id)
update_user.username = body["username"]
update_user.name = body["name"]
update_user.birth = body["birth"]
Expand All @@ -154,29 +166,24 @@ def read_edit_delete_user(request,id):
update_user.nickname = body["nickname"]

update_user.save()

update_user_json={
"id" : update_user.id,
"username" : update_user.username,
"name" : update_user.name,
"birth" : update_user.birth,
"bio" : update_user.bio,
"avatar" : update_user.avatar,
"nickname" : update_user.nickname,
update_user_json = {
"id": update_user.id,
"username": update_user.username,
"name": update_user.name,
"birth": update_user.birth,
"bio": update_user.bio,
"avatar": update_user.avatar,
"nickname": update_user.nickname,
}

json_res = json.dumps(
{
"status": 200,
"success": True,
"message": "수정 성공",
"data": update_user_json
},
ensure_ascii=False
)
json_res = json.dumps({
"success": True,
"message": "수정 성공",
"data": update_user_json
}, ensure_ascii=False)

return HttpResponse(
json_res,
content_type=u"application/json; charset=utf-8",
status=200
)
)
Loading