api change user
This commit is contained in:
parent
c3476a4a5f
commit
e5ade4637c
@ -22,7 +22,7 @@ from alkatorapi.views import (
|
|||||||
results, photos,
|
results, photos,
|
||||||
payment_result, payment_state,
|
payment_result, payment_state,
|
||||||
invoice, upload_files,
|
invoice, upload_files,
|
||||||
login_status,
|
login_status, change_racer,
|
||||||
)
|
)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
@ -32,6 +32,7 @@ urlpatterns = [
|
|||||||
path('api/login', login),
|
path('api/login', login),
|
||||||
path('api/login_status', login_status),
|
path('api/login_status', login_status),
|
||||||
path('api/logout', logout),
|
path('api/logout', logout),
|
||||||
|
path('api/change_racer', change_racer),
|
||||||
#path('api/register', register),
|
#path('api/register', register),
|
||||||
path('api/results', results),
|
path('api/results', results),
|
||||||
path('api/photos', photos),
|
path('api/photos', photos),
|
||||||
|
@ -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
|
from alkator.settings import COMGATE_MERCHANT, COMGATE_SECRET, COMGATE_TEST
|
||||||
|
|
||||||
|
|
||||||
|
DEADLINE = date(2025, 10, 5)
|
||||||
|
ALKATOR_CLASS = 3
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def register_user(request):
|
def register_user(request):
|
||||||
if not request.POST['first_name']:
|
if not request.POST['first_name']:
|
||||||
@ -72,9 +76,7 @@ def logout(request):
|
|||||||
def register_racer(request):
|
def register_racer(request):
|
||||||
if not request.user.is_authenticated:
|
if not request.user.is_authenticated:
|
||||||
return HttpResponse('{"reason":"Je potřeba se přihlásit!"}', status=400, content_type='application/json')
|
return HttpResponse('{"reason":"Je potřeba se přihlásit!"}', status=400, content_type='application/json')
|
||||||
ALKATOR_CLASS = 3
|
if date.today() >= DEADLINE:
|
||||||
|
|
||||||
if date.today() >= date(2025, 10, 5):
|
|
||||||
return HttpResponse('{"reason":"Too late!"}', status=400, content_type='application/json')
|
return HttpResponse('{"reason":"Too late!"}', status=400, content_type='application/json')
|
||||||
if not request.POST.get('agreement'):
|
if not request.POST.get('agreement'):
|
||||||
return HttpResponse('{"reason":"Je potřeba souhlasit se zpracováním údajů!"}', status=400, content_type='application/json')
|
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,
|
'price': price,
|
||||||
'curr': 'CZK',
|
'curr': 'CZK',
|
||||||
'method': 'ALL',
|
'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,
|
'email': user.email,
|
||||||
'fullName': f"{profile.first_name} {profile.last_name}",
|
'fullName': f"{profile.first_name} {profile.last_name}",
|
||||||
'refId': f'{racer.invoice_id}',
|
'refId': f'{racer.invoice_id}',
|
||||||
@ -170,6 +172,7 @@ def login_status(request):
|
|||||||
"first_name": racer.first_name,
|
"first_name": racer.first_name,
|
||||||
"last_name": racer.last_name,
|
"last_name": racer.last_name,
|
||||||
"email": racer.email,
|
"email": racer.email,
|
||||||
|
"phone": racer.phone,
|
||||||
"team": racer.team,
|
"team": racer.team,
|
||||||
"date_of_birth": racer.date_of_birth.strftime("%Y-%m-%d"),
|
"date_of_birth": racer.date_of_birth.strftime("%Y-%m-%d"),
|
||||||
"paid": racer.paid,
|
"paid": racer.paid,
|
||||||
@ -177,6 +180,29 @@ def login_status(request):
|
|||||||
}), content_type='application/json')
|
}), 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
|
#@csrf_exempt
|
||||||
#def register(request):
|
#def register(request):
|
||||||
# ALKATOR_CLASS = 2
|
# ALKATOR_CLASS = 2
|
||||||
|
@ -208,6 +208,7 @@ class Main extends Component {
|
|||||||
<th scope="col">Email</th>
|
<th scope="col">Email</th>
|
||||||
<th scope="col">Team</th>
|
<th scope="col">Team</th>
|
||||||
<th scope="col">Datum narození</th>
|
<th scope="col">Datum narození</th>
|
||||||
|
<th scope="col">Telefon</th>
|
||||||
<th scope="col">Zaplatil</th>
|
<th scope="col">Zaplatil</th>
|
||||||
<th scope="col">Změnit</th>
|
<th scope="col">Změnit</th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -220,8 +221,9 @@ class Main extends Component {
|
|||||||
<td>{racer.email}</td>
|
<td>{racer.email}</td>
|
||||||
<td>{racer.team}</td>
|
<td>{racer.team}</td>
|
||||||
<td>{racer.date_of_birth}</td>
|
<td>{racer.date_of_birth}</td>
|
||||||
|
<td>{racer.phone}</td>
|
||||||
<td>{racer.paid?"Zaplatil":"Nezaplatil"}</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>)}
|
</tr>)}
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user