diff --git a/backend/webapp/prototype/filehandler/views.py b/backend/webapp/prototype/filehandler/views.py index f0ee70e..218395f 100644 --- a/backend/webapp/prototype/filehandler/views.py +++ b/backend/webapp/prototype/filehandler/views.py @@ -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) + diff --git a/backend/webapp/prototype/urls.py b/backend/webapp/prototype/urls.py index 5c4a5dd..19b9e64 100644 --- a/backend/webapp/prototype/urls.py +++ b/backend/webapp/prototype/urls.py @@ -25,7 +25,8 @@ urlpatterns = [ path('prototype/form/', views.model_form_upload, name='model_form_upload'), path('admin/', admin.site.urls), path('discussions/', views.discussions), - path('visualize/', views.visualize) + path('visualize/', views.visualize), + path('user/', views.user) ] if settings.DEBUG: