From 91922bb5d4a524746632ed3e7f331fd829be3b3a Mon Sep 17 00:00:00 2001 From: "Andreas (@xAndy) Zimmermann" Date: Fri, 29 Apr 2022 02:22:47 +0200 Subject: [PATCH] add exponential registration backoff, change registration text --- .../migrations/0003_logintoken_send_count.py | 18 ++++++++++++++++++ shiftregister/app/models.py | 5 ++++- shiftregister/app/urls.py | 2 +- shiftregister/app/views.py | 6 +++++- 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 shiftregister/app/migrations/0003_logintoken_send_count.py diff --git a/shiftregister/app/migrations/0003_logintoken_send_count.py b/shiftregister/app/migrations/0003_logintoken_send_count.py new file mode 100644 index 0000000..0ebb417 --- /dev/null +++ b/shiftregister/app/migrations/0003_logintoken_send_count.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.4 on 2022-04-29 00:19 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("app", "0002_message_sent_at"), + ] + + operations = [ + migrations.AddField( + model_name="logintoken", + name="send_count", + field=models.IntegerField(default=0), + ), + ] diff --git a/shiftregister/app/models.py b/shiftregister/app/models.py index 9a1f6b2..c2eb1fb 100644 --- a/shiftregister/app/models.py +++ b/shiftregister/app/models.py @@ -115,12 +115,15 @@ class LoginToken(models.Model): ) helper = models.ForeignKey(Helper, on_delete=models.CASCADE) sent_at = models.DateTimeField(auto_now_add=True) + send_count = models.IntegerField(default=0) def send(self): - text = f"Hallo {self.helper.name}, hier ist dein Registrierungslink zum Kontaktfestival http://short.url{self.get_absolute_url()}" + text = f"Dein Registrierungslink zum Helfer*inensystem: https://kontakt.rocks/{self.get_absolute_url()} \nWenn du dich nicht registiert hast, ignoriere diese SMS." + print("msglen", len(text)) msg = Message(to=self.helper, text=text) msg.save() self.sent_at = timezone.now() + self.send_count += 1 self.save() # import here to break import cycle from .tasks import send_message diff --git a/shiftregister/app/urls.py b/shiftregister/app/urls.py index f1190d8..f01b9a1 100644 --- a/shiftregister/app/urls.py +++ b/shiftregister/app/urls.py @@ -4,7 +4,7 @@ from . import views urlpatterns = [ path("", views.index, name="index"), - path("login/", views.login, name="token_login"), + path("l/", views.login, name="token_login"), path("logout", views.logout, name="token_logout"), path("register", views.register, name="register"), path("shift/", views.shift, name="shift"), diff --git a/shiftregister/app/views.py b/shiftregister/app/views.py index ffb5af8..0dbcdf8 100644 --- a/shiftregister/app/views.py +++ b/shiftregister/app/views.py @@ -10,6 +10,7 @@ from django.contrib import messages import datetime from .decorators import event_state from dynamic_preferences.registries import global_preferences_registry +import math global_preferences = global_preferences_registry.manager() @@ -118,7 +119,10 @@ def register(request): messages.INFO, f"DEBUG:{token.get_absolute_url()}", ) - if token.sent_at < (timezone.now() - datetime.timedelta(minutes=10)): + if token.sent_at < ( + timezone.now() + - datetime.timedelta(minutes=math.pow(10, token.send_count)) + ): token.send() return render(request, "register.html", context)