Add confirmation page before getting the code to avoid bots

parent e26105bf
......@@ -20,6 +20,9 @@ class Action(models.Model):
def unused_codes(self):
return self.codes.filter(active=True, used=False)
def unclaimed_codes(self):
return self.codes.filter(active=True, claimed=False, used=False)
def claimed_codes(self):
return self.codes.filter(active=True, claimed=True)
......
......@@ -23,6 +23,7 @@ urlpatterns = [
path('add_codes/<uuid:uuid>/', views.ActionAddCodesView.as_view(), name='add_codes'),
path('toggle/<uuid:uuid>/', views.ActionToggleView.as_view(), name='toggle'),
path('get/<uuid:uuid>/', views.ActionGetCodeView.as_view(), name='get'),
path('getcode/<uuid:uuid>/', views.ActionClaimCodeView.as_view(), name='getcode'),
path('scan/<uuid:uuid>/', views.CodeScanView.as_view(), name='scan'),
path('claim/<uuid:uuid>/', views.CodeClaimView.as_view(), name='claim'),
]
......@@ -54,13 +54,22 @@ class ActionToggleView(LoginRequiredMixin, DetailView):
self.object.save()
return redirect("detail", self.object.uuid)
class ActionGetCodeView(DetailView):
model = Action
template_name = "action_get.html"
def get_object(self, queryset=None):
return self.get_queryset().get(uuid=self.kwargs['uuid'])
class ActionClaimCodeView(DetailView):
model = Action
template_name = "action_claim.html"
def get_object(self, queryset=None):
return self.get_queryset().get(uuid=self.kwargs['uuid'])
def get_context_data(self, **kwargs):
context = super(ActionGetCodeView, self).get_context_data(**kwargs)
context = super(ActionClaimCodeView, self).get_context_data(**kwargs)
if self.object.active:
# Grab the code from session or a new one
......@@ -78,10 +87,6 @@ class ActionGetCodeView(DetailView):
return context
def get_object(self, queryset=None):
return self.get_queryset().get(uuid=self.kwargs['uuid'])
class CodeScanView(LoginRequiredMixin, TemplateView):
template_name = "scan.html"
......
{% extends "base.html" %}
{% load staticfiles form_tools %}
{% block title %}{% if action.active %}{% if code %}Code generated!{% else %}No codes left!{% endif %}{% else %}Action not active!{% endif %}{% endblock %}
{% block css %}
<link rel="stylesheet" href="{% static 'style.css' %}">
{% endblock %}
{% block body_class %}{% if action.active %}{% if code %}scan-success{% else %}scan-warning{% endif %}{% else %}scan-inactive{% endif %}{% endblock %}
{% block content %}
<div class="container">
<div class="card">
<div class="card-body">
{% if action.active %}
{% if code %}
<h5 class="card-title">Code generated!</h5>
<p class="card-text">
{% if DEBUG %}<a href="{% url 'claim' uuid=code.uuid %}">{% endif %}
<img src="{{ code.png_qrcode }}" alt="QR-code" />
{% if DEBUG %}</a>{% endif %}
</p>
<p class="card-text">
Please save this code and show it to the bartenders during the {{ code.action.name }} to get a free drink of choice! (beer, cola or fanta)
</p>
{% else %}
<h5 class="card-title">All codes are gone!</h5>
<p class="card-text warn">:(</p>
<p class="card-text">
All codes have already been taken, sorry!
</p>
{% endif %}
{% else %}
<h5 class="card-title">Action not active!</h5>
<p class="card-text inactive"></p>
<p class="card-text">
This action is over or has not started yet!
</p>
{% endif %}
</div>
</div>
</div>
{% endblock %}
{% extends "base.html" %}
{% load staticfiles form_tools %}
{% block title %}{% if action.active %}{% if code %}Code generated!{% else %}No codes left!{% endif %}{% else %}Action not active!{% endif %}{% endblock %}
{% block title %}{% if action.active %}{% if action.unclaimed_codes|length > 0 %}Claim code!{% else %}No codes left!{% endif %}{% else %}Action not active!{% endif %}{% endblock %}
{% block css %}
<link rel="stylesheet" href="{% static 'style.css' %}">
{% endblock %}
{% block body_class %}{% if action.active %}{% if code %}scan-success{% else %}scan-warning{% endif %}{% else %}scan-inactive{% endif %}{% endblock %}
{% block body_class %}{% if action.active %}{% if action.unclaimed_codes|length > 0 %}scan-pending{% else %}scan-warning{% endif %}{% else %}scan-inactive{% endif %}{% endblock %}
{% block content %}
<div class="container">
<div class="card">
<div class="card-body">
{% if action.active %}
{% if code %}
<h5 class="card-title">Code generated!</h5>
{% if action.unclaimed_codes|length > 0 %}
<h5 class="card-title">Claim a promotion code!</h5>
<a class="btn btn-info claimbtn" href="{% url 'getcode' uuid=object.uuid %}"></a>
<p class="card-text">
{% if DEBUG %}<a href="{% url 'claim' uuid=code.uuid %}">{% endif %}
<img src="{{ code.png_qrcode }}" alt="QR-code" />
{% if DEBUG %}</a>{% endif %}
</p>
<p class="card-text">
Please save this code and show it to the bartenders during the {{ code.action.name }} to get a free drink of choice! (beer, cola or fanta)
Click the button to claim a code for a free drink (beer, cola, fanta) at the {{ object.name }}!
</p>
{% else %}
<h5 class="card-title">All codes are gone!</h5>
......
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