API Endpoint for Users Registration
This commit is contained in:
parent
f050e13290
commit
c25b3f66d2
@ -3,6 +3,7 @@ from django.conf import settings
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.http import JsonResponse, HttpResponse
|
||||
from django.contrib.auth.models import User
|
||||
import json
|
||||
|
||||
from prototype.filehandler.models import Document, Forum
|
||||
@ -71,3 +72,19 @@ def visualize(request, id):
|
||||
return HttpResponse('Error: Couldn\'t list posts', status=406)
|
||||
else:
|
||||
return HttpResponse('Error: Unacceptable HTTP method', status=406)
|
||||
|
||||
@csrf_exempt
|
||||
def user(request):
|
||||
if request.method == 'POST':
|
||||
login = request.POST['login']
|
||||
try:
|
||||
user = User.objects.get(username = login)
|
||||
except User.DoesNotExist:
|
||||
user = User.objects.create_user(username = login, email = login, password = request.POST['password'])
|
||||
return HttpResponse('User created successfully!', status=200)
|
||||
except Exception:
|
||||
return HttpResponse('Error: Couldn\'t register user', status=406)
|
||||
return HttpResponse('Error: User already exists', status=406)
|
||||
else:
|
||||
return HttpResponse('Error: Unacceptable HTTP method', status=406)
|
||||
|
||||
|
@ -25,7 +25,8 @@ urlpatterns = [
|
||||
path('prototype/form/', views.model_form_upload, name='model_form_upload'),
|
||||
path('admin/', admin.site.urls),
|
||||
path('discussions/<int:id>', views.discussions),
|
||||
path('visualize/<int:id>', views.visualize)
|
||||
path('visualize/<int:id>', views.visualize),
|
||||
path('user/', views.user)
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
|
Loading…
Reference in New Issue
Block a user