Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def cancel_reservation(request, token):
s = URLSafeSerializer('some_secret_key', salt='cancel_reservation')
ret = s.loads(token)
event_id = ret['event_id']
user_id = ret['user_id']
event = Event.objects.get(pk=event_id)
user = CustomUser.objects.get(pk=user_id)
context = {'event': event, 'user': user}
attendees = event.attendees.all()
if user in attendees:
event.attendees.remove(user)
event.available_seats += 1
event.save()
return render(request, 'mail/cancel_ok.html', context)
else:
return render(request, 'mail/cancel_failed.html', context)
def session_encode(string_input):
data = (random_word(16)+"."+string_input+"."+random_word(16))
s = urlsafe('generate:openedoo')
b = s.dumps(data)
return b
def query_signer():
return itsdangerous.URLSafeSerializer(current_app.config['SECRET_KEY'],
salt='fdt-sql-query')
def signer(salt):
return URLSafeSerializer(current_app.config['SECRET_KEY'] + salt)
def sign_auth_path(next_path):
"""returns a URL-safe signed next_path"""
# next_path must start with a /
if not next_path.startswith('/'):
abort(503)
# sign the next_path
notary = itsdangerous.URLSafeSerializer(app.secret_key)
next_path_signed = notary.dumps(next_path)
return url_for('authenticate', next=next_path_signed)
def set_present(request):
if request.method != 'POST':
# TODO change this
return HttpResponse("Circulez, il n'y a rien à voir")
else:
serial = URLSafeSerializer('some_secret_key',
salt='presence')
data = serial.loads(request.POST['idents'])
event_id = data['event_id']
user_id = data['user_id']
person = CustomUser.objects.get(pk=user_id)
event = Event.objects.get(pk=event_id)
event.attendees.remove(person)
event.presents.add(person)
action.send(request.user, verb="a validé la présence de", action_object=person, target=event)
return JsonResponse({'status': "OK", 'user_id': user_id})
def encode(something):
"""Encode something with SECRET_KEY."""
secret_key = current_app.config.get('SECRET_KEY')
s = URLSafeSerializer(secret_key)
return s.dumps(something)
def unserialize(secret, data):
return URLSafeSerializer(secret).loads(data)
def query_signer():
return itsdangerous.URLSafeSerializer(current_app.config['SECRET_KEY'],
salt='fdt-sql-query')