diff --git a/db.sqlite3 b/db.sqlite3 index 4fe2729..d78df19 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/users/__pycache__/urls.cpython-39.pyc b/users/__pycache__/urls.cpython-39.pyc index 79bb0af..7d80830 100644 Binary files a/users/__pycache__/urls.cpython-39.pyc and b/users/__pycache__/urls.cpython-39.pyc differ diff --git a/users/__pycache__/views.cpython-39.pyc b/users/__pycache__/views.cpython-39.pyc index bbcf085..d74c5e2 100644 Binary files a/users/__pycache__/views.cpython-39.pyc and b/users/__pycache__/views.cpython-39.pyc differ diff --git a/users/urls.py b/users/urls.py index 5a45ef2..8c29ac9 100644 --- a/users/urls.py +++ b/users/urls.py @@ -5,5 +5,6 @@ urlpatterns = [ path('', views.loginuser, name="login"), - path('/getusers/', views.getusers, name="getusers") + path('/getusers//', views.getusers, name="getusers"), + path('/createuser/', views.createuser, name="createuser") ] diff --git a/users/views.py b/users/views.py index e21bd13..33f4acb 100644 --- a/users/views.py +++ b/users/views.py @@ -9,19 +9,28 @@ from datetime import datetime, timedelta -def createuser(email, password, avatar, name): - request = { - 'email' : email, - 'name' : name, - "password" : password, - "avatar" : avatar - } - serializer = UserDetailserializers(data=request) - if serializer.is_valid(): - serializer.save() +@api_view(['POST']) +def createuser(request): + email = request.data.get('email') + password = request.data.get('password') + url = request.data.get("avatar") + name = request.data.get("name") + if UserDetails.objects.filter(email=email).exists() and UserDetails.objects.filter(password=password): + return Response({"Restult": "User Already Exists"}) else: - print(request.data) - return Response(serializer.data) + request = { + 'email': email, + 'name': name, + "password": password, + "avatar": url + } + serializer = UserDetailserializers(data=request) + if serializer.is_valid(): + serializer.save() + else: + print(request.data) + return Response(serializer.data) + @api_view(['POST']) def loginuser(request): @@ -36,7 +45,7 @@ def loginuser(request): } return Response(response_data) else: - createuser(email, password, url, name) + return Response({"Result": "Register To login"}) @api_view(['GET']) @@ -45,4 +54,4 @@ def getusers(request, pk): x = UserDetails.objects.values_list('email', 'name') return Response(x) else: - return Response("invalid token") \ No newline at end of file + return Response("invalid token")