Projet

Général

Profil

0001-warn-user-after-account-self-deletion-26910.patch

Paul Marillonnet, 15 novembre 2018 10:52

Télécharger (4,94 ko)

Voir les différences:

Subject: [PATCH] warn user after account self-deletion (#26910)

 src/authentic2/registration_backend/views.py     |  1 +
 .../account_delete_notification_body.html        |  9 +++++++++
 .../account_delete_notification_body.txt         |  4 ++++
 .../account_delete_notification_subject.txt      |  1 +
 src/authentic2/utils.py                          | 16 ++++++++++++++++
 tests/test_views.py                              |  4 +++-
 6 files changed, 34 insertions(+), 1 deletion(-)
 create mode 100644 src/authentic2/templates/authentic2/account_delete_notification_body.html
 create mode 100644 src/authentic2/templates/authentic2/account_delete_notification_body.txt
 create mode 100644 src/authentic2/templates/authentic2/account_delete_notification_subject.txt
src/authentic2/registration_backend/views.py
389 389
        return kwargs
390 390

  
391 391
    def form_valid(self, form):
392
        utils.send_account_deletion_mail(self.request, self.request.user)
392 393
        models.DeletedUser.objects.delete_user(self.request.user)
393 394
        self.request.user.email += '#%d' % random.randint(1, 10000000)
394 395
        self.request.user.email_verified = False
src/authentic2/templates/authentic2/account_delete_notification_body.html
1
{% load i18n %}
2
<html>
3
  <body style="max-width: 90ex">
4
    {% blocktrans %}
5
        <p>{{ full_name }},</p>
6
        <p>Your account deletion request on {{ site }} has been received.</p>
7
    {% endblocktrans %}
8
  </body>
9
</html>
src/authentic2/templates/authentic2/account_delete_notification_body.txt
1
{% load i18n %}{% autoescape off %}{% blocktrans %}{{ full_name }},
2

  
3
Your account deletion request on {{ site }} has been received.
4
{% endblocktrans %}{% endautoescape %}
src/authentic2/templates/authentic2/account_delete_notification_subject.txt
1
{% load i18n %}{% autoescape off %}{% trans "Account deletion request on" %} {{ site }}{% endautoescape %}
src/authentic2/utils.py
693 693
                registration_url)
694 694

  
695 695

  
696
def send_account_deletion_mail(request, user):
697
    '''Send an account deletion notification mail to an user.
698

  
699
       Can raise an smtplib.SMTPException
700
    '''
701
    logger = logging.getLogger(__name__)
702
    context = {
703
        'full_name': user.get_full_name(),
704
        'site': request.get_host()}
705
    template_names = [
706
        'authentic2/account_delete_notification_%s' % user.ou,
707
        'authentic2/account_delete_notification']
708
    send_templated_mail(user.email, template_names, context, request=request)
709
    logger.info(u'account deletion mail sent to %s', user.email)
710

  
711

  
696 712
def build_reset_password_url(user, request=None, next_url=None, set_random_password=True):
697 713
    '''Build a reset password URL'''
698 714
    from .compat import default_token_generator
tests/test_views.py
21 21
    page = page.form.submit('cancel').follow()
22 22

  
23 23

  
24
def test_account_delete(app, simple_user):
24
def test_account_delete(app, simple_user, mailoutbox):
25 25
    assert simple_user.is_active
26
    assert not len(mailoutbox)
26 27
    page = login(app, simple_user, path=reverse('delete_account'))
27 28
    page.form.set('password', simple_user.username)
28 29
    # FIXME: webtest does not set the Referer header, so the logout page will always ask for
29 30
    # confirmation under tests
30 31
    response = page.form.submit(name='submit').follow()
31 32
    response = response.form.submit()
33
    assert len(mailoutbox) == 1
32 34
    assert not User.objects.get(pk=simple_user.pk).is_active
33 35
    assert urlparse(response.location).path == '/'
34 36
    response = response.follow().follow()
35
-