Commit fc6a300a authored by Matthieu Gautier's avatar Matthieu Gautier

Do not store user information in a cookie.

Fix #35
parent 44049b31
......@@ -53,19 +53,6 @@ class MessageCreate(FormView):
def get_success_url(self):
return reverse('message_thank')
def get_initial(self):
stored_user_serial = self.request.session.get('user_serial')
if not stored_user_serial:
return {}
user = User.objects.get(serial=stored_user_serial)
return {
'author': user.full_name,
'motto': user.extra,
'birth_year': user.birth_year,
'address': user.camp_address,
'phone': user.phone,
}
def form_valid(self, form):
# Some variables
author = form.cleaned_data['author']
......@@ -80,38 +67,24 @@ class MessageCreate(FormView):
title = "Message de {}".format(author)
# Store user information in a cookie
stored_user_serial = self.request.session.get('user_serial')
user = None
if stored_user_serial:
user = User.objects.get(serial=stored_user_serial)
if user:
user.full_name = author
user.birth_year = form.cleaned_data['birth_year']
user.phone = form.cleaned_data['phone']
user.camp_address = form.cleaned_data['address']
user.extra = motto
user.save()
else:
user_serial = base_user_serial = 'listener_{}'.format(author)[:40]
user_serial_id = 0
while True:
try:
user = User.objects.create(
serial=user_serial,
full_name=author,
birth_year=form.cleaned_data['birth_year'],
phone=form.cleaned_data['phone'],
camp_address=form.cleaned_data['address'],
extra=motto)
break
except IntegrityError:
user_serial_id += 1
extension = "~{}".format(user_serial_id)
user_serial = "{}{}".format(
base_user_serial[:40-len(extension)],
extension)
self.request.session['user_serial'] = user_serial
user_serial = base_user_serial = 'listener_{}'.format(author)[:40]
user_serial_id = 0
while True:
try:
user = User.objects.create(
serial=user_serial,
full_name=author,
birth_year=form.cleaned_data['birth_year'],
phone=form.cleaned_data['phone'],
camp_address=form.cleaned_data['address'],
extra=motto)
break
except IntegrityError:
user_serial_id += 1
extension = "~{}".format(user_serial_id)
user_serial = "{}{}".format(
base_user_serial[:40-len(extension)],
extension)
# Create the document
document = None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment