Skip to content

Commit

Permalink
Updated the Register Funcation
Browse files Browse the repository at this point in the history
  • Loading branch information
pravee42 committed Dec 18, 2021
1 parent 65bdf07 commit a1f0924
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
Binary file modified db.sqlite3
Binary file not shown.
Binary file modified users/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file modified users/__pycache__/views.cpython-39.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@

urlpatterns = [
path('', views.loginuser, name="login"),
path('/getusers/<int:pk>', views.getusers, name="getusers")
path('/getusers/<int:pk>/', views.getusers, name="getusers"),
path('/createuser/', views.createuser, name="createuser")
]
37 changes: 23 additions & 14 deletions users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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'])
Expand All @@ -45,4 +54,4 @@ def getusers(request, pk):
x = UserDetails.objects.values_list('email', 'name')
return Response(x)
else:
return Response("invalid token")
return Response("invalid token")

0 comments on commit a1f0924

Please sign in to comment.