Fix venueless token creation

Do not generate token or checkin if user does not have a ticket.
Clear existing token if user no longer has a ticket.
This commit is contained in:
Joel Addison 2021-01-22 22:20:46 +10:00
parent 0a6d53162f
commit bf46c82fe4
4 changed files with 24 additions and 7 deletions

View file

@ -41,8 +41,10 @@
</div> </div>
</div> </div>
{% else %} {% else %}
{% if purchased %}
{% flag "venueless_dashboard" %} {% flag "venueless_dashboard" %}
{% venueless_login_url as venueless_url %}
{% if venueless_url %}
<div class="row"> <div class="row">
<div class="col-12 mb-3"> <div class="col-12 mb-3">
<h3>Join the Conference</h3> <h3>Join the Conference</h3>
@ -52,8 +54,8 @@
</div> </div>
</div> </div>
</div> </div>
{% endflag %}
{% endif %} {% endif %}
{% endflag %}
<div class="row"> <div class="row">
<div class="col-md-6 mb-3 mb-md-0"> <div class="col-md-6 mb-3 mb-md-0">

View file

@ -163,6 +163,14 @@ def ticket_type(context):
@register.simple_tag(takes_context=True) @register.simple_tag(takes_context=True)
def venueless_login_url(context): def venueless_login_url(context):
# Check that they have a ticket first (only item from category 1)
items = registrasion_tags.items_purchased(context, 1)
if not items:
return ''
# Get token from checkin
user=context.request.user user=context.request.user
checkin = CheckIn.objects.get_or_create(user=user)[0] checkin = CheckIn.objects.get_or_create(user=user)[0]
if checkin.venueless_token:
return f'{settings.VENUELESS_URL}/#token={checkin.venueless_token}' return f'{settings.VENUELESS_URL}/#token={checkin.venueless_token}'
return ''

View file

@ -167,7 +167,7 @@ class CheckIn(models.Model):
self.venueless_traits = ",".join(traits) self.venueless_traits = ",".join(traits)
updated = True updated = True
if not self._venueless_token: if not self.venueless_traits or not self._venueless_token:
self._venueless_token = self._generate_venueless_token() self._venueless_token = self._generate_venueless_token()
updated = True updated = True
@ -177,9 +177,12 @@ class CheckIn(models.Model):
return self._venueless_token return self._venueless_token
def _get_venueless_traits(self): def _get_venueless_traits(self):
traits = ["attendee"] """ Returns a list of traits based on the user's ticket """
ticket_type = self.user.attendee.ticket_type ticket_type = self.user.attendee.ticket_type
if not ticket_type:
return []
traits = ["attendee"]
if ticket_type == "Conference Volunteer": if ticket_type == "Conference Volunteer":
traits.append("volunteer") traits.append("volunteer")
@ -207,6 +210,8 @@ class CheckIn(models.Model):
def _generate_venueless_token(self): def _generate_venueless_token(self):
""" Generate token for Venueless login """ """ Generate token for Venueless login """
if not self.venueless_traits:
return ""
issued_at = datetime.datetime.utcnow() issued_at = datetime.datetime.utcnow()
expiry = settings.LCA_END + datetime.timedelta(days=1) expiry = settings.LCA_END + datetime.timedelta(days=1)

View file

@ -62,6 +62,8 @@ class Attendee(models.Model):
) )
if len(tickets) > 1: if len(tickets) > 1:
raise ValueError("Too many tickets for attendee %s", self) raise ValueError("Too many tickets for attendee %s", self)
if len(tickets) == 0:
return ""
return tickets[0].product.name return tickets[0].product.name
class AttendeeProfileBase(models.Model): class AttendeeProfileBase(models.Model):