auth_fc: send verification link upon account creation (#73148)
This commit is contained in:
parent
1c22e90637
commit
de9759f1a9
|
@ -6,5 +6,7 @@
|
|||
|
||||
<p>{% trans "You have just created an account using FranceConnect." %}</p>
|
||||
|
||||
{% include "emails/button-link.html" with url=login_url label=_("Login now") %}
|
||||
<p>{% trans "You can complete your account validation by clicking on the button below." %}</p>
|
||||
|
||||
{% include "emails/button-link.html" with url=verification_link label=_("Complete your account validation") %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
{% trans "You have just created an account using FranceConnect." %}
|
||||
|
||||
{% trans "You can login by clicking on the link below:" %}
|
||||
{{ login_url }}
|
||||
{% trans "You can complete your account validation by clicking on the link below:" %}
|
||||
{{ verification_link }}
|
||||
{% endautoescape %}{% endblock %}
|
||||
|
|
|
@ -496,15 +496,29 @@ 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)
|
||||
|
||||
token = models.FcEmailVerificationToken.create(user)
|
||||
verification_link = request.build_absolute_uri(
|
||||
reverse('fc-verification', kwargs={'token': token.value})
|
||||
)
|
||||
utils_misc.send_templated_mail(
|
||||
user,
|
||||
template_names=['authentic2_auth_fc/registration_success'],
|
||||
context={
|
||||
'user': user,
|
||||
'login_url': request.build_absolute_uri(settings.LOGIN_URL),
|
||||
'verification_link': verification_link,
|
||||
},
|
||||
request=self.request,
|
||||
)
|
||||
token.sent = True
|
||||
token.save()
|
||||
messages.warning(
|
||||
request,
|
||||
_(
|
||||
'Your account has been created. Please complete your registration by '
|
||||
'consulting the account validation link sent to you by email.'
|
||||
),
|
||||
)
|
||||
# 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')
|
||||
|
|
|
@ -128,7 +128,7 @@ def test_create(settings, app, franceconnect, hooks, service, mailoutbox):
|
|||
for body in (mailoutbox[0].body, mailoutbox[0].alternatives[0][0]):
|
||||
assert 'Hi Ÿuñe Frédérique,' in body
|
||||
assert 'You have just created an account using FranceConnect.' in body
|
||||
assert 'https://testserver/login/' in body
|
||||
assert 'You can complete your account validation' in body
|
||||
|
||||
assert user.verified_attributes.first_name == 'Ÿuñe'
|
||||
assert user.verified_attributes.last_name == 'Frédérique'
|
||||
|
@ -379,8 +379,9 @@ def test_login_with_missing_required_attributes(settings, app, franceconnect):
|
|||
assert models.FcAccount.objects.count() == 1
|
||||
cookie = decode_cookie(app.cookies['messages'])
|
||||
if isinstance(cookie, list):
|
||||
assert len(cookie) == 1
|
||||
cookie = cookie[0].message
|
||||
assert len(cookie) == 2
|
||||
assert 'Your account has been created. Please complete your registration' in cookie[0].message
|
||||
cookie = cookie[1].message
|
||||
assert 'The following fields are mandatory for account creation: Title' in cookie
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue