From 588fd6162873e6db6d199c6fd1d59ecdcffb026e Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Thu, 3 Nov 2022 16:38:44 +0100 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 diff --git a/src/authentic2_auth_fc/templates/authentic2_auth_fc/registration_success_body.html b/src/authentic2_auth_fc/templates/authentic2_auth_fc/registration_success_body.html new file mode 100644 index 000000000..80383ee28 --- /dev/null +++ b/src/authentic2_auth_fc/templates/authentic2_auth_fc/registration_success_body.html @@ -0,0 +1,10 @@ +{% extends "emails/body_base.html" %} +{% load i18n %} + +{% block content %} +

{% blocktrans %}Hi {{ user }},{% endblocktrans %}

+ +

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

+ + {% include "emails/button-link.html" with url=login_url label=_("Login now") %} +{% endblock %} diff --git a/src/authentic2_auth_fc/templates/authentic2_auth_fc/registration_success_body.txt b/src/authentic2_auth_fc/templates/authentic2_auth_fc/registration_success_body.txt new file mode 100644 index 000000000..19d7c187f --- /dev/null +++ b/src/authentic2_auth_fc/templates/authentic2_auth_fc/registration_success_body.txt @@ -0,0 +1,7 @@ +{% extends "emails/body_base.txt" %}{% load i18n %}{% block content %}{% autoescape off %}{% blocktrans %}Hi {{ user }},{% endblocktrans %} + +{% trans "You have just created an account using FranceConnect." %} + +{% trans "You can login by clicking on the link below:" %} + {{ login_url }} +{% endautoescape %}{% endblock %} diff --git a/src/authentic2_auth_fc/templates/authentic2_auth_fc/registration_success_subject.txt b/src/authentic2_auth_fc/templates/authentic2_auth_fc/registration_success_subject.txt new file mode 100644 index 000000000..acc45811b --- /dev/null +++ b/src/authentic2_auth_fc/templates/authentic2_auth_fc/registration_success_subject.txt @@ -0,0 +1,4 @@ +{% extends "emails/subject.txt" %} +{% load i18n %} + +{% block email-subject %}{% trans "Account creation using FranceConnect" %}{% endblock %} diff --git a/src/authentic2_auth_fc/views.py b/src/authentic2_auth_fc/views.py index 8388ee25b..8e4ab138d 100644 --- a/src/authentic2_auth_fc/views.py +++ b/src/authentic2_auth_fc/views.py @@ -482,6 +482,14 @@ class LoginOrLinkView(View): if created: logger.info('auth_fc: new account "%s" created with FranceConnect sub "%s"', user, sub) hooks.call_hooks('event', name='fc-create', user=user, sub=sub, request=request) + utils_misc.send_templated_mail( + user, + template_names=['authentic2_auth_fc/registration_success'], + context={ + 'login_url': request.build_absolute_uri(settings.LOGIN_URL), + }, + request=self.request, + ) # FC account creation does not rely on the registration_completion generic view. # Registration event has to be recorded here: request.journal.record('user.registration', user=user, how='france-connect') diff --git a/tests/auth_fc/test_auth_fc.py b/tests/auth_fc/test_auth_fc.py index 7f5a58251..cd49e5bce 100644 --- a/tests/auth_fc/test_auth_fc.py +++ b/tests/auth_fc/test_auth_fc.py @@ -104,7 +104,7 @@ def test_login_username_autofocus(settings, app, franceconnect): assert response.pyquery('#id_username').attr.autofocus is not None -def test_create(settings, app, franceconnect, hooks, service): +def test_create(settings, app, franceconnect, hooks, service, mailoutbox): # test direct creation set_service(app, service) response = app.get('/login/?next=/idp/') @@ -122,6 +122,14 @@ def test_create(settings, app, franceconnect, hooks, service): Event.objects.filter(type__name='user.registration', user=user).which_references(service).count() == 1 ) + # check registration email + assert len(mailoutbox) == 1 + assert mailoutbox[0].subject == 'Account creation using FranceConnect' + for body in (mailoutbox[0].body, mailoutbox[0].alternatives[0][0]): + assert 'Hi AnonymousUser,' in body + assert 'You have just created an account using FranceConnect.' in body + assert 'http://testserver/login/' in body + assert user.verified_attributes.first_name == 'Ÿuñe' assert user.verified_attributes.last_name == 'Frédérique' assert path(response.location) == '/idp/' -- 2.35.1