api change user

This commit is contained in:
Martin Quarda 2024-10-10 09:48:38 +02:00
parent c3476a4a5f
commit e5ade4637c
3 changed files with 35 additions and 6 deletions

View File

@ -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),

View File

@ -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

View File

@ -208,6 +208,7 @@ class Main extends Component {
<th scope="col">Email</th>
<th scope="col">Team</th>
<th scope="col">Datum narození</th>
<th scope="col">Telefon</th>
<th scope="col">Zaplatil</th>
<th scope="col">Změnit</th>
</tr>
@ -220,8 +221,9 @@ class Main extends Component {
<td>{racer.email}</td>
<td>{racer.team}</td>
<td>{racer.date_of_birth}</td>
<td>{racer.phone}</td>
<td>{racer.paid?"Zaplatil":"Nezaplatil"}</td>
<td><button onClick={(e) => {console.log(změnit)}}>Změnit</button></td>
<td><button type="button" class="btn btn-light" onClick={(e) => {console.log("změnit :" + racer.invoice_id)}}>Změnit</button></td>
</tr>)}
</tbody>