This commit is contained in:
Martin Quarda 2024-10-09 17:35:06 +02:00
parent 0dd620cd79
commit 687166338c

View File

@ -4,7 +4,8 @@ from django.template.response import TemplateResponse
from django.views.decorators.csrf import csrf_exempt
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.models import User as DjangoUser
from django.contrib.auth import authenticate, login
from django.contrib.auth import authenticate
from django.contrib.auth import login as auth_login
from django.core.mail import send_mail, mail_admins
from django.utils.datastructures import MultiValueDictKeyError
from datetime import date, datetime, timedelta
@ -43,7 +44,8 @@ def register_user(request):
)
profile = Profile(user=user, first_name=request.POST['first_name'], last_name=request.POST['last_name'], address=request.POST['address'])
profile.save()
login(request, user)
auth_login(request, user)
return HttpResponse('{"success":"Úspěšná registrace!"}', content_type='application/json')
@csrf_exempt
@ -53,7 +55,7 @@ def login(request):
except MultiValueDictKeyError:
return HttpResponse('{"reason":"Nezadané jméno nebo heslo!"}', status=400, content_type='application/json')
if user is not None:
login(request, user)
auth_login(request, user)
return HttpResponse('{"success":"Úspěšně přihlášen uživatel '+ user.email + '"}', content_type='application/json')
else:
return HttpResponse('{"reason":"Nesprávné jméno nebo heslo!"}', status=400, content_type='application/json')