|
@ -10,6 +10,7 @@ from django.http import Http404,HttpResponseBadRequest,HttpResponseRedirect |
|
|
from django.db.models import Q |
|
|
from django.db.models import Q |
|
|
from django.views.decorators.csrf import ensure_csrf_cookie |
|
|
from django.views.decorators.csrf import ensure_csrf_cookie |
|
|
from django.contrib.auth import authenticate, login, get_user_model, logout |
|
|
from django.contrib.auth import authenticate, login, get_user_model, logout |
|
|
|
|
|
from django.contrib.auth.models import User |
|
|
from django.contrib.auth.mixins import LoginRequiredMixin |
|
|
from django.contrib.auth.mixins import LoginRequiredMixin |
|
|
from django.db import transaction |
|
|
from django.db import transaction |
|
|
from dal import autocomplete |
|
|
from dal import autocomplete |
|
@ -1025,83 +1026,75 @@ def logoutView(request): |
|
|
return render(request, 'seminar/login.html', {'form': form}) |
|
|
return render(request, 'seminar/login.html', {'form': form}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def prihlaska_log_gdpr_safe(logger, gdpr_logger, msg, form_data): |
|
|
|
|
|
msg = "{}, form_hash:{}".format(msg,hash(form_data)) |
|
|
|
|
|
logger.warn(msg) |
|
|
|
|
|
gdpr_logger.warn(msg+", form:{}".format(form_data)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def prihlaskaView(request): |
|
|
def prihlaskaView(request): |
|
|
logger = logging.getLogger('seminar.prihlaska') |
|
|
generic_logger = logging.getLogger('seminar.prihlaska') |
|
|
|
|
|
err_logger = logging.getLogger('seminar.prihlaska.problem') |
|
|
|
|
|
form_logger = logging.getLogger('seminar.prihlaska.form') |
|
|
if request.method == 'POST': |
|
|
if request.method == 'POST': |
|
|
form = PrihlaskaForm(request.POST) |
|
|
form = PrihlaskaForm(request.POST) |
|
|
# TODO vyresit, co se bude v jakych situacich zobrazovat |
|
|
# TODO vyresit, co se bude v jakych situacich zobrazovat |
|
|
if form.is_valid(): |
|
|
if form.is_valid(): |
|
|
print("Form valid") |
|
|
generic_logger.info("Form valid") |
|
|
try: |
|
|
fcd = form.cleaned_data |
|
|
# mame jiz email v databazi? |
|
|
form_hash = hash(fcd) |
|
|
o = Osoba.objects.get(email=form.cleaned_data['email']) |
|
|
form_logger.info(fcd,form_hash=form_hash) |
|
|
print("Email existuje: {}".format(form.cleaned_data)) |
|
|
|
|
|
# TODO seřvat a nepustit dál |
|
|
|
|
|
return HttpResponseRedirect('/thanks/') |
|
|
|
|
|
except ObjectDoesNotExist: |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
User = get_user_model() |
|
|
|
|
|
try: |
|
|
|
|
|
u = User.objects.get(username=form.cleaned_data['username']) |
|
|
|
|
|
print("Username existuje: {}".format(form.cleaned_data)) |
|
|
|
|
|
# TODO seřvat a nepustit dál |
|
|
|
|
|
return HttpResponseRedirect('/thanks/') |
|
|
|
|
|
|
|
|
|
|
|
except ObjectDoesNotExist: |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
with transaction.atomic(): |
|
|
with transaction.atomic(): |
|
|
u = User.objects.create_user( |
|
|
u = User.objects.create_user( |
|
|
username=form.cleaned_data['username'], |
|
|
username=fcd['username'], |
|
|
password=form.cleaned_data['password'], |
|
|
password=fcd['password'], |
|
|
email = form.cleaned_data['email']) |
|
|
email = fcd['email']) |
|
|
u.save() |
|
|
u.save() |
|
|
|
|
|
|
|
|
o = Osoba( |
|
|
o = Osoba( |
|
|
jmeno = form.cleaned_data['jmeno'], |
|
|
jmeno = fcd['jmeno'], |
|
|
prijmeni = form.cleaned_data['prijmeni'], |
|
|
prijmeni = fcd['prijmeni'], |
|
|
pohlavi_muz = form.cleaned_data['pohlavi_muz'], |
|
|
pohlavi_muz = fcd['pohlavi_muz'], |
|
|
email = form.cleaned_data['email'], |
|
|
email = fcd['email'], |
|
|
telefon = form.cleaned_data.get('telefon',''), |
|
|
telefon = fcd.get('telefon',''), |
|
|
datum_narozeni = form.cleaned_data.get('datum_narozeni',None), |
|
|
datum_narozeni = fcd.get('datum_narozeni',None), |
|
|
datum_souhlasu_udaje = date.today(), |
|
|
datum_souhlasu_udaje = date.today(), |
|
|
datum_registrace = date.today(), |
|
|
datum_registrace = date.today(), |
|
|
ulice = form.cleaned_data.get('ulice',''), |
|
|
ulice = fcd.get('ulice',''), |
|
|
mesto = form.cleaned_data.get('mesto',''), |
|
|
mesto = fcd.get('mesto',''), |
|
|
psc = form.cleaned_data.get('psc',''), |
|
|
psc = fcd.get('psc',''), |
|
|
poznamka = str(form.cleaned_data) |
|
|
poznamka = str(fcd) |
|
|
) |
|
|
) |
|
|
if form.cleaned_data.get('spam',False): |
|
|
if fcd.get('spam',False): |
|
|
o.datum_souhlasu_zasilani = date.today() |
|
|
o.datum_souhlasu_zasilani = date.today() |
|
|
if form.cleaned_data.get('stat','') in ('CZ','SK'): |
|
|
if fcd.get('stat','') in ('CZ','SK'): |
|
|
o.stat = form.cleaned_data['stat'] |
|
|
o.stat = fcd['stat'] |
|
|
else: |
|
|
else: |
|
|
pass |
|
|
# Unknown country - log it |
|
|
#TODO jak budeme resit jine staty? |
|
|
msg = "Unknown country {}".format(fcd['stat_text']) |
|
|
|
|
|
err_logger.warn(msg,form_hash=form_hash) |
|
|
|
|
|
|
|
|
o.save() |
|
|
o.save() |
|
|
o.user = u |
|
|
o.user = u |
|
|
o.save() |
|
|
o.save() |
|
|
|
|
|
|
|
|
r = Resitel( |
|
|
r = Resitel( |
|
|
rok_maturity = form.cleaned_data['rok_maturity'], |
|
|
rok_maturity = fcd['rok_maturity'], |
|
|
zasilat = form.cleaned_data['zasilat'] |
|
|
zasilat = fcd['zasilat'] |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
r.save() |
|
|
r.save() |
|
|
r.osoba = o |
|
|
r.osoba = o |
|
|
if form.cleaned_data.get('skola'): |
|
|
if fcd.get('skola'): |
|
|
r.skola = form.cleaned_data['skola'] |
|
|
r.skola = fcd['skola'] |
|
|
else: |
|
|
else: |
|
|
pass |
|
|
# Unknown school - log it |
|
|
#TODO doplnit skolu, kdyz neni v seznamu |
|
|
msg = "Unknown school {}, {}".format(fcd['skola_nazev'],fcd['skola_adresa']) |
|
|
|
|
|
err_logger.warn(msg,form_hash=form_hash) |
|
|
r.save() |
|
|
r.save() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO logovat jednotlive validni formulare do souboru |
|
|
|
|
|
print(form.cleaned_data) |
|
|
|
|
|
logger.info(form.cleaned_data) |
|
|
|
|
|
return HttpResponseRedirect('/thanks/') |
|
|
return HttpResponseRedirect('/thanks/') |
|
|
|
|
|
|
|
|
# if a GET (or any other method) we'll create a blank form |
|
|
# if a GET (or any other method) we'll create a blank form |
|
|