diff --git a/alkator/urls.py b/alkator/urls.py index b8bd433..a44605e 100644 --- a/alkator/urls.py +++ b/alkator/urls.py @@ -22,7 +22,7 @@ from alkatorapi.views import ( results, photos, payment_result, payment_state, invoice, upload_files, - login_status, + login_status, change_racer, ) urlpatterns = [ @@ -32,6 +32,7 @@ urlpatterns = [ path('api/login', login), path('api/login_status', login_status), path('api/logout', logout), + path('api/change_racer', change_racer), #path('api/register', register), path('api/results', results), path('api/photos', photos), diff --git a/alkatorapi/views.py b/alkatorapi/views.py index dc209f1..a7b5978 100644 --- a/alkatorapi/views.py +++ b/alkatorapi/views.py @@ -22,6 +22,10 @@ from .models import User, ALKATOR_CHOICES_DICT, ALKATOR_CLASSES, Profile, Racer from alkator.settings import COMGATE_MERCHANT, COMGATE_SECRET, COMGATE_TEST +DEADLINE = date(2025, 10, 5) +ALKATOR_CLASS = 3 + + @csrf_exempt def register_user(request): if not request.POST['first_name']: @@ -72,9 +76,7 @@ def logout(request): def register_racer(request): if not request.user.is_authenticated: return HttpResponse('{"reason":"Je potřeba se přihlásit!"}', status=400, content_type='application/json') - ALKATOR_CLASS = 3 - - if date.today() >= date(2025, 10, 5): + if date.today() >= DEADLINE: return HttpResponse('{"reason":"Too late!"}', status=400, content_type='application/json') if not request.POST.get('agreement'): return HttpResponse('{"reason":"Je potřeba souhlasit se zpracováním údajů!"}', status=400, content_type='application/json') @@ -133,7 +135,7 @@ def register_racer(request): 'price': price, 'curr': 'CZK', 'method': 'ALL', - 'label': 'Startovné na závod Alkátor Race Studené 2024', + 'label': 'Startovné na závod Alkátor Race Dolní Čermná 2025', 'email': user.email, 'fullName': f"{profile.first_name} {profile.last_name}", 'refId': f'{racer.invoice_id}', @@ -170,6 +172,7 @@ def login_status(request): "first_name": racer.first_name, "last_name": racer.last_name, "email": racer.email, + "phone": racer.phone, "team": racer.team, "date_of_birth": racer.date_of_birth.strftime("%Y-%m-%d"), "paid": racer.paid, @@ -177,6 +180,29 @@ def login_status(request): }), content_type='application/json') +def change_racer(request): + try: + if request.user != racer.profile.user: + return HttpResponse('{"reason":"Nedostatečná práva!"}', status=400, content_type='application/json') + if date.today() >= DEADLINE: + return HttpResponse('{"reason":"Too late!"}', status=400, content_type='application/json') + if not request.POST['first_name']: + return HttpResponse('{"reason":"Jméno je povinné!"}', status=400, content_type='application/json') + if not request.POST['last_name']: + return HttpResponse('{"reason":"Přijmení je povinné!"}', status=400, content_type='application/json') + racer = Racer.objects.get(request.POST['invoice_id']) + racer.first_name = request.POST['first_name'] + racer.last_name = request.POST['last_name'] + racer.email = request.POST['email'] + racer.phone = request.POST['phone'] + racer.team = request.POST['team'] + racer.date_of_birth = request.POST['date_of_birth'] + racer.save() + return HttpResponse('{"success":"Úspěšně uloženo."}', content_type='application/json') + except MultiValueDictKeyError: + return HttpResponse('{"reason":"Nějaký údaj chybí!"}', status=400, content_type='application/json') + + #@csrf_exempt #def register(request): # ALKATOR_CLASS = 2 diff --git a/frontend/src/scripts/index.js b/frontend/src/scripts/index.js index e598617..e5de0f6 100644 --- a/frontend/src/scripts/index.js +++ b/frontend/src/scripts/index.js @@ -208,6 +208,7 @@ class Main extends Component {