Skip to content

Commit bb14f4e

Browse files
committed
- Create user API 추가
1 parent b843583 commit bb14f4e

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

djangoPractice/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# SECURITY WARNING: don't run with debug turned on in production!
2626
DEBUG = True
2727

28-
ALLOWED_HOSTS = []
28+
ALLOWED_HOSTS = ['django-env.eba-xfvw9mxz.us-west-2.elasticbeanstalk.com', '127.0.0.1', 'localhost']
2929

3030
CORS_ORIGIN_ALLOW_ALL = True
3131
CSRF_COOKIE_SECURE = True

user/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
from user import views
44

55
urlpatterns = [
6-
path('login/', views.login, name='login')
6+
path('login/', views.login, name='login'),
7+
path('create/', views.create, name='create_user')
78
]

user/views.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
from django.contrib.auth import authenticate
22

33
# Create your views here.
4-
from django.views.decorators.csrf import csrf_exempt
4+
from django.http import HttpResponse
55
from rest_framework.authtoken.models import Token
66
from rest_framework.decorators import permission_classes, api_view
77
from rest_framework.permissions import AllowAny
88
from rest_framework.response import Response
99
from rest_framework.status import HTTP_400_BAD_REQUEST, HTTP_404_NOT_FOUND, HTTP_200_OK
1010

11+
from polls.models import User
12+
1113

1214
@api_view(['POST'])
1315
@permission_classes((AllowAny,))
@@ -25,3 +27,16 @@ def login(request):
2527

2628
token, _ = Token.objects.get_or_create(user=user)
2729
return Response({'token': token.key}, status=HTTP_200_OK)
30+
31+
@api_view(['POST'])
32+
@permission_classes((AllowAny,))
33+
def create(request):
34+
email = request.data.get('email')
35+
password = request.data.get('password')
36+
fullname = request.data.get('fullname')
37+
38+
user = User.objects.create_user(email=email, password=password, full_name=fullname)
39+
if user:
40+
return HttpResponse(status=200)
41+
else:
42+
return HttpResponse(status=400)

0 commit comments

Comments
 (0)