From 65a91c11100d68f61a7ec69e7bda4fbcd10a1005 Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Fri, 17 Apr 2020 14:08:54 +0200 Subject: [PATCH] Show warning with delay before account suspension for users --- users/management/commands/clean_notyetactive.py | 2 +- users/models.py | 9 +++++++++ users/templates/users/email_confirmation_request | 6 ++++++ users/templates/users/profil.html | 2 +- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/users/management/commands/clean_notyetactive.py b/users/management/commands/clean_notyetactive.py index d6c9a701..d1857096 100644 --- a/users/management/commands/clean_notyetactive.py +++ b/users/management/commands/clean_notyetactive.py @@ -32,7 +32,7 @@ class Command(BaseCommand): def handle(self, *args, **options): """First deleting invalid invoices, and then deleting the users""" - days = OptionalUser.get_cached_value("delete_notyetactive") + days = OptionalUser.get_cached_value("disable_emailnotyetconfirmed") users_to_delete = ( User.objects.filter(Q(state=User.STATE_NOT_YET_ACTIVE) | Q(state=User.STATE_DISABLED)) .filter(registered__lte=timezone.now() - timedelta(days=days)) diff --git a/users/models.py b/users/models.py index 12f88c56..1e0db421 100755 --- a/users/models.py +++ b/users/models.py @@ -62,6 +62,7 @@ from django.core.mail import send_mail from django.core.urlresolvers import reverse from django.db import transaction from django.utils import timezone +from datetime import timedelta from django.contrib.auth.models import ( AbstractBaseUser, BaseUserManager, @@ -803,6 +804,13 @@ class User( ) return + def confirm_email_before_date(self): + if self.email_change_date is None or self.state != self.STATE_EMAIL_NOT_YET_CONFIRMED: + return None + + days = OptionalUser.get_cached_value("disable_emailnotyetconfirmed") + return str(self.email_change_date + timedelta(days=days)) + def confirm_email_address_mail(self, request): """Prend en argument un request, envoie un mail pour confirmer l'adresse""" @@ -821,6 +829,7 @@ class User( reverse("users:process", kwargs={"token": req.token}) ), "expire_in": str(GeneralOption.get_cached_value("req_expire_hrs")), + "confirm_before": self.confirm_email_before_date(), } send_mail( "Confirmation de l'email de %(name)s / Email confirmation for " diff --git a/users/templates/users/email_confirmation_request b/users/templates/users/email_confirmation_request index b3385e02..65e20c13 100644 --- a/users/templates/users/email_confirmation_request +++ b/users/templates/users/email_confirmation_request @@ -9,6 +9,9 @@ de vos équipements, votre compte, vos factures, et tous les services proposés Contactez les administrateurs si vous n'êtes pas à l'origine de cette requête. Ce lien expirera dans {{ expire_in }} heures. +S'il a expiré, vous pouvez renvoyer un mail de confirmation depuis votre compte {{ site_name }}. + +Attention : Si vous ne confirmez pas votre email avant le {{ confirm_before }}, votre compte sera suspendu. Respectueusement, @@ -27,6 +30,9 @@ the services offered on the network. Contact the administrators if you didn't request this. This link will expire in {{ expire_in }} hours. +If it has expired, you can send a new confirmation email from your account on {{ site_name }}. + +Warning: If you do not confirm your email before {{ confirm_before }}, your account will be suspended. Regards, diff --git a/users/templates/users/profil.html b/users/templates/users/profil.html index 2cbfe9ce..84871045 100644 --- a/users/templates/users/profil.html +++ b/users/templates/users/profil.html @@ -42,7 +42,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% if users.state == users.STATE_EMAIL_NOT_YET_CONFIRMED %}
- {% blocktrans %}Please confirm your email address.{% endblocktrans %} + {% blocktrans %}Please confirm your email address before {{ users.confirm_email_before_date }}, or your account will be suspended.{% endblocktrans %}
{% blocktrans %}Didn't receive the email?{% endblocktrans %}