-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user): authentification via un lien magique envoyé par email (#804)
## Description 🎸 En complément de l'authentification via `Pro Connect` (#731), permettre à un utlisateur de s'authentifier via un lien magique envoyé par email. 🎸 Nécessaire pour les utilisateurs n'appartenant pas à une organisation, car ils ne peuvent pas utiliser `Pro Connect` 🐻 La vue principale de connexion est désormais `LoginView`. Elle permet de recevoir un magic link ou de se connecter avec ProConnect. 🐻 Si l'utilisateur se connecte avec un lien magic, une variable est positionnée dans sa session pour determiner le mécanisme de déconnection à actionner. 🐻 `LoginView` n'est plus accessible si l'utilisateur est authentifié.⚠️ edge case Un utilisateur demande un magic link, puis se connecter avec ProConnect, puis clique sur le magic link. La déconnection pourrait être celle du magic link (pas de déco ProConnect). Pas d'effet de bord catastrophique attendu. ## Type de changement 🎢 Nouvelle fonctionnalité (changement non cassant qui ajoute une fonctionnalité). 🚧 technique ### Points d'attention 🦺 ajout de la méthode `clean_next_url` pour limiter les risques sur les redirections 🦺 en dev, les magic link sont enregistrés dans `EmailSentTrack` 🦺 ref https://www.honeybadger.io/blog/options-for-passwordless-authentication-in-django/ 🦺 ref https://stackoverflow.com/a/46236585 🦺 pour une PR suivante : ajouter le contrôle sur `BlockedEmail` et sur `BlockedDomainName` pour prévenir d'eventuels spammers ### Captures d'écran (optionnel) LoginView ![image](https://github.com/user-attachments/assets/85b209f4-2ee3-4294-9499-a5bf89d69374) CreateUserView ![image](https://github.com/user-attachments/assets/f1434872-fcf0-42ca-9f3c-7143232a4788) Login Link Sent ![image](https://github.com/user-attachments/assets/a0e26f6d-bf13-4f13-8aee-60e6e684b42f)
- Loading branch information
1 parent
c0f89a2
commit 64e04a3
Showing
29 changed files
with
1,141 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -353,14 +353,15 @@ | |
|
||
# SENDINBLUE | ||
# --------------------------------------- | ||
SIB_URL = "https://api.brevo.com/v3/" | ||
SIB_URL = os.getenv("SIB_URL", "http://test.com") | ||
SIB_SMTP_URL = os.path.join(SIB_URL, "smtp/email") | ||
SIB_CONTACTS_URL = os.path.join(SIB_URL, "contacts/import") | ||
SIB_CONTACT_LIST_URL = os.path.join(SIB_URL, "contacts/lists") | ||
|
||
SIB_API_KEY = os.getenv("SIB_API_KEY", "set-sib-api-key") | ||
DEFAULT_FROM_EMAIL = os.getenv("DEFAULT_FROM_EMAIL", "[email protected]") | ||
|
||
SIB_MAGIC_LINK_TEMPLATE = 31 | ||
SIB_UNANSWERED_QUESTION_TEMPLATE = 10 | ||
SIB_ONBOARDING_LIST = 5 | ||
SIB_NEW_MESSAGES_TEMPLATE = 28 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...munaute/notification/migrations/0010_alter_emailsenttrack_kind_alter_notification_kind.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Generated by Django 5.0.9 on 2024-11-13 13:44 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("notification", "0009_alter_emailsenttrack_kind_notification"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="emailsenttrack", | ||
name="kind", | ||
field=models.CharField( | ||
choices=[ | ||
("first_reply", "Première réponse à un sujet"), | ||
("following_replies", "Réponses suivantes"), | ||
("onboarding", "Onboarding d'un nouvel utilisateur"), | ||
("pending_topic", "Question sans réponse"), | ||
("magic_link", "Lien de connexion magique"), | ||
], | ||
max_length=20, | ||
verbose_name="type", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="notification", | ||
name="kind", | ||
field=models.CharField( | ||
choices=[ | ||
("first_reply", "Première réponse à un sujet"), | ||
("following_replies", "Réponses suivantes"), | ||
("onboarding", "Onboarding d'un nouvel utilisateur"), | ||
("pending_topic", "Question sans réponse"), | ||
("magic_link", "Lien de connexion magique"), | ||
], | ||
max_length=20, | ||
verbose_name="type", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{% extends "board_base.html" %} | ||
{% load i18n %} | ||
{% block sub_title %} | ||
{% trans "Sign in" %} | ||
{% endblock sub_title %} | ||
{% block content %} | ||
<section class="s-title-01 mt-lg-5"> | ||
<div class="s-title-01__container container"> | ||
<div class="s-title-01__row row"> | ||
<div class="s-title-01__col col-12"> | ||
<h1 class="s-title-01__title h1"> | ||
<strong>{% trans "Sign in" %}</strong> | ||
</h1> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
<section class="s-section"> | ||
<div class="s-section__container container"> | ||
<div class="s-section__row row"> | ||
<div class="s-section__col col-12 col-lg-7"> | ||
<div class="card"> | ||
<div class="card-body"> | ||
Bonjour {{ email }} et bienvenue dans la communauté de l'inclusion, encore quelques informations avant de vous envoyer le lien. | ||
</div> | ||
<div class="c-form"> | ||
<form method="post" action="." enctype="multipart/form-data" novalidate> | ||
{% csrf_token %} | ||
{% if form.non_field_errors %} | ||
{% for error in form.non_field_errors %} | ||
<div class="alert alert-danger"> | ||
<i class="icon-exclamation-sign"></i> | ||
{{ error }} | ||
</div> | ||
{% endfor %} | ||
{% endif %} | ||
{% include "partials/form_field.html" with field=form.email %} | ||
{% include "partials/form_field.html" with field=form.first_name %} | ||
{% include "partials/form_field.html" with field=form.last_name %} | ||
<div class="form-actions"> | ||
<input type="hidden" name="next" value="{{ request.GET.next }}" /> | ||
<input type="submit" class="btn btn-large btn-primary" value="{% trans "Login with your email" %}" /> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{% load i18n %} | ||
<a href="{% url 'users:login' %}?next={{ request.path }}" rel="nofollow" class="btn btn-outline-primary btn-ico btn-block">{% trans "Login | Sign in" %}</a> |
6 changes: 6 additions & 0 deletions
6
lacommunaute/templates/registration/includes/logout_link.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% if request.session.MAGIC_LINK %} | ||
{% url 'users:logout' as logout_url %} | ||
{% else %} | ||
{% url 'openid_connect:logout' as logout_url %} | ||
{% endif %} | ||
<a class="dropdown-item text-danger" id="js-logout" href="{{ logout_url }}"">Déconnexion</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{% extends "layouts/base.html" %} | ||
{% load static %} | ||
{% load i18n %} | ||
{% load theme_inclusion %} | ||
{% block title %}Connexion {{ block.super }}{% endblock %} | ||
{% block meta_description %} | ||
{% trans "Login | Sign in" %} | ||
{% endblock meta_description %} | ||
{% block content %} | ||
<section class="s-title-01 mt-lg-5"> | ||
<div class="s-title-01__container container"> | ||
<div class="s-title-01__row row"> | ||
<div class="s-title-01__col col-lg-8 col-12"> | ||
<h1 class="s-title-01__title h1">{% trans "Login | Sign in" %}</h1> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
<section class="s-section"> | ||
<div class="s-section__container container"> | ||
<div class="s-section__row row"> | ||
<div class="s-section__col col-12 col-lg-7"> | ||
Un lien de connexion vous a été envoyé à l'adresse {{ email }}. Veuillez vérifier votre boîte de réception et cliquer sur le lien pour vous connecter. | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
{% endblock content %} |
49 changes: 49 additions & 0 deletions
49
lacommunaute/templates/registration/login_with_magic_link.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{% extends "layouts/base.html" %} | ||
{% load static %} | ||
{% load i18n %} | ||
{% load theme_inclusion %} | ||
{% block title %}Connexion {{ block.super }}{% endblock %} | ||
{% block meta_description %} | ||
{% trans "Login | Sign in" %} | ||
{% endblock meta_description %} | ||
{% block content %} | ||
<section class="s-title-01 mt-lg-5"> | ||
<div class="s-title-01__container container"> | ||
<div class="s-title-01__row row"> | ||
<div class="s-title-01__col col-lg-8 col-12"> | ||
<h1 class="s-title-01__title h1">{% trans "Login | Sign in" %}</h1> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
<section class="s-section"> | ||
<div class="s-section__container container"> | ||
<div class="s-section__row row"> | ||
<div class="s-section__col col-12 col-lg-7"> | ||
<div class="card"> | ||
<div class="c-form"> | ||
<a href="{% url 'openid_connect:authorize' %}?next={{ next }}" rel="nofollow" class="btn btn-outline-primary btn-ico btn-block">Se connecter avec Pro Connect</a> | ||
<hr class="my-5" data-it-text="ou"> | ||
<form method="post" action="." enctype="multipart/form-data" novalidate> | ||
{% csrf_token %} | ||
{% if form.non_field_errors %} | ||
{% for error in form.non_field_errors %} | ||
<div class="alert alert-danger"> | ||
<i class="icon-exclamation-sign"></i> | ||
{{ error }} | ||
</div> | ||
{% endfor %} | ||
{% endif %} | ||
{% include "partials/form_field.html" with field=form.email %} | ||
<div class="form-actions"> | ||
<input type="hidden" name="next" value="{{ request.GET.next }}" /> | ||
<input type="submit" class="btn btn-large btn-primary" value="{% trans "Login with your email" %}" /> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from django import forms | ||
|
||
|
||
class LoginForm(forms.Form): | ||
email = forms.EmailField( | ||
label="", | ||
widget=forms.EmailInput(attrs={"placeholder": "Votre adresse email"}), | ||
) | ||
|
||
|
||
class CreateUserForm(forms.Form): | ||
first_name = forms.CharField(label="Votre prénom", max_length=150) | ||
last_name = forms.CharField(label="Votre nom", max_length=150) | ||
email = forms.EmailField(label="Votre adresse email") |
19 changes: 19 additions & 0 deletions
19
lacommunaute/users/migrations/0003_alter_user_identity_provider.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 5.0.9 on 2024-11-12 10:54 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("users", "0002_user_identity_provider"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="user", | ||
name="identity_provider", | ||
field=models.CharField( | ||
choices=[("IC", "Inclusion Connect"), ("PC", "Pro Connect"), ("ML", "Magic Link")], max_length=2 | ||
), | ||
), | ||
] |
Empty file.
Oops, something went wrong.