2023-12-15 02:52:49 +01:00
|
|
|
from hmac import compare_digest
|
|
|
|
|
2023-12-13 23:58:00 +01:00
|
|
|
from django.contrib import messages
|
2023-12-15 02:52:49 +01:00
|
|
|
from django.shortcuts import redirect
|
2023-12-15 02:48:31 +01:00
|
|
|
from django.urls import reverse
|
2023-12-13 23:58:00 +01:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2023-12-15 02:48:31 +01:00
|
|
|
from django.views.generic import FormView, TemplateView
|
|
|
|
from pretalx.common.mixins.views import EventPermissionRequired
|
|
|
|
|
2023-12-13 23:58:00 +01:00
|
|
|
from .forms import MusicrateSettingsForm
|
|
|
|
|
|
|
|
|
2023-12-15 02:52:49 +01:00
|
|
|
class JoinView(TemplateView):
|
|
|
|
template_name = "pretalx_musicrate/join.html"
|
|
|
|
|
|
|
|
def validate_token(self, token):
|
|
|
|
if compare_digest(
|
|
|
|
token.encode("utf-8"),
|
|
|
|
self.request.event.pretalx_musicrate_settings.join_token.encode("utf-8"),
|
|
|
|
):
|
|
|
|
return True
|
|
|
|
messages.error(self.request, _("Invalid token"))
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_context_data(self, token_valid=False, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context["token_valid"] = token_valid
|
|
|
|
return context
|
|
|
|
|
|
|
|
def get(self, request, *args, token, **kwargs):
|
|
|
|
token_valid = self.validate_token(token)
|
|
|
|
return super().get(request, *args, token_valid=token_valid, **kwargs)
|
|
|
|
|
|
|
|
def post(self, request, *args, token, **kwargs):
|
|
|
|
token_valid = self.validate_token(token)
|
|
|
|
if token_valid:
|
|
|
|
return redirect(request.path)
|
|
|
|
return self.render_to_response(
|
|
|
|
self.get_context_data(token_valid=token_valid, **kwargs)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-12-15 02:48:31 +01:00
|
|
|
class MusicrateSettingsView(EventPermissionRequired, FormView):
|
2023-12-13 23:58:00 +01:00
|
|
|
permission_required = "orga.change_settings"
|
|
|
|
template_name = "pretalx_musicrate/settings.html"
|
|
|
|
form_class = MusicrateSettingsForm
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return self.request.path
|
|
|
|
|
|
|
|
def get_form_kwargs(self):
|
|
|
|
kwargs = super().get_form_kwargs()
|
|
|
|
kwargs["event"] = self.request.event
|
|
|
|
return kwargs
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
form.save()
|
2023-12-14 00:57:15 +01:00
|
|
|
messages.success(
|
2023-12-14 19:36:50 +01:00
|
|
|
self.request, _("The pretalx-musicrate settings were updated.")
|
2023-12-14 00:57:15 +01:00
|
|
|
)
|
2023-12-13 23:58:00 +01:00
|
|
|
return super().form_valid(form)
|
2023-12-15 02:48:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
class QRCodeView(EventPermissionRequired, TemplateView):
|
|
|
|
permission_required = "orga.view_submissions"
|
|
|
|
template_name = "pretalx_musicrate/qrcode.html"
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context["contents"] = self.request.build_absolute_uri(
|
|
|
|
reverse(
|
|
|
|
"plugins:pretalx_musicrate:join",
|
|
|
|
kwargs={
|
|
|
|
"event": self.request.event.slug,
|
|
|
|
"token": self.request.event.pretalx_musicrate_settings.join_token,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return context
|