Projet

Général

Profil

0001-auth_fc-send-email-on-registration-65839.patch

Valentin Deniaud, 08 novembre 2022 17:49

Télécharger (5,1 ko)

Voir les différences:

Subject: [PATCH] auth_fc: send email on registration (#65839)

 .../authentic2_auth_fc/registration_success_body.html  | 10 ++++++++++
 .../authentic2_auth_fc/registration_success_body.txt   |  7 +++++++
 .../registration_success_subject.txt                   |  4 ++++
 src/authentic2_auth_fc/views.py                        |  8 ++++++++
 tests/auth_fc/test_auth_fc.py                          | 10 +++++++++-
 5 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 src/authentic2_auth_fc/templates/authentic2_auth_fc/registration_success_body.html
 create mode 100644 src/authentic2_auth_fc/templates/authentic2_auth_fc/registration_success_body.txt
 create mode 100644 src/authentic2_auth_fc/templates/authentic2_auth_fc/registration_success_subject.txt
src/authentic2_auth_fc/templates/authentic2_auth_fc/registration_success_body.html
1
{% extends "emails/body_base.html" %}
2
{% load i18n %}
3

  
4
{% block content %}
5
  <p>{% blocktrans  %}Hi {{ user }},{% endblocktrans %}</p>
6

  
7
  <p>{% trans "You have just created an account using FranceConnect." %}</p>
8

  
9
  {% include "emails/button-link.html" with url=login_url label=_("Login now") %}
10
{% endblock %}
src/authentic2_auth_fc/templates/authentic2_auth_fc/registration_success_body.txt
1
{% extends "emails/body_base.txt" %}{% load i18n %}{% block content %}{% autoescape off %}{% blocktrans %}Hi {{ user }},{% endblocktrans %}
2

  
3
{% trans "You have just created an account using FranceConnect." %}
4

  
5
{% trans "You can login by clicking on the link below:" %}
6
  {{ login_url }}
7
{% endautoescape %}{% endblock %}
src/authentic2_auth_fc/templates/authentic2_auth_fc/registration_success_subject.txt
1
{% extends "emails/subject.txt" %}
2
{% load i18n %}
3

  
4
{% block email-subject %}{% trans "Account creation using FranceConnect" %}{% endblock %}
src/authentic2_auth_fc/views.py
482 482
            if created:
483 483
                logger.info('auth_fc: new account "%s" created with FranceConnect sub "%s"', user, sub)
484 484
                hooks.call_hooks('event', name='fc-create', user=user, sub=sub, request=request)
485
                utils_misc.send_templated_mail(
486
                    user,
487
                    template_names=['authentic2_auth_fc/registration_success'],
488
                    context={
489
                        'login_url': request.build_absolute_uri(settings.LOGIN_URL),
490
                    },
491
                    request=self.request,
492
                )
485 493
                # FC account creation does not rely on the registration_completion generic view.
486 494
                # Registration event has to be recorded here:
487 495
                request.journal.record('user.registration', user=user, how='france-connect')
tests/auth_fc/test_auth_fc.py
104 104
    assert response.pyquery('#id_username').attr.autofocus is not None
105 105

  
106 106

  
107
def test_create(settings, app, franceconnect, hooks, service):
107
def test_create(settings, app, franceconnect, hooks, service, mailoutbox):
108 108
    # test direct creation
109 109
    set_service(app, service)
110 110
    response = app.get('/login/?next=/idp/')
......
122 122
        Event.objects.filter(type__name='user.registration', user=user).which_references(service).count() == 1
123 123
    )
124 124

  
125
    # check registration email
126
    assert len(mailoutbox) == 1
127
    assert mailoutbox[0].subject == 'Account creation using FranceConnect'
128
    for body in (mailoutbox[0].body, mailoutbox[0].alternatives[0][0]):
129
        assert 'Hi AnonymousUser,' in body
130
        assert 'You have just created an account using FranceConnect.' in body
131
        assert 'http://testserver/login/' in body
132

  
125 133
    assert user.verified_attributes.first_name == 'Ÿuñe'
126 134
    assert user.verified_attributes.last_name == 'Frédérique'
127 135
    assert path(response.location) == '/idp/'
128
-