-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A new process in which the user submits their email address and is redirected to the correct login method instead of being depended on to choose which service they use to connect. Includes also a graphical redesign, and some redirection options to the registration process
- Loading branch information
1 parent
44842fe
commit 06b789a
Showing
13 changed files
with
210 additions
and
49 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,19 @@ | ||
{% load static %} | ||
{% load theme_inclusion %} | ||
{% load django_bootstrap5 %} | ||
|
||
<div class="modal-dialog modal-dialog-centered"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h3 class="modal-title" id="message-modal-{{ forloop.counter }}-label"> | ||
{% if "email_does_not_exist" in message.extra_tags %} | ||
Adresse e-mail inconnue | ||
{% else %} | ||
Le connexion a échoué | ||
{% endif %} | ||
</h3> | ||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Fermer"></button> | ||
</div> | ||
{{ message }} | ||
</div> | ||
</div> |
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 |
---|---|---|
@@ -1,13 +1,57 @@ | ||
from allauth.account.forms import LoginForm | ||
from django import forms | ||
from django.conf import settings | ||
from django.contrib import messages | ||
from django.core.exceptions import ValidationError | ||
from django.urls import reverse | ||
from django.utils.html import format_html | ||
from django.utils.safestring import mark_safe | ||
|
||
from itou.openid_connect.errors import format_error_modal_content | ||
from itou.users.enums import IdentityProvider | ||
from itou.users.models import User | ||
|
||
|
||
class FindExistingUserViaEmailForm(forms.Form): | ||
""" | ||
Validates only the email field. Displays a modal to user if email not in use | ||
""" | ||
|
||
email = forms.EmailField( | ||
label="Adresse e-mail", | ||
required=True, | ||
widget=forms.TextInput( | ||
attrs={"type": "email", "placeholder": "[email protected]", "autocomplete": "email", "autofocus": True} | ||
), | ||
) | ||
|
||
def __init__(self, *args, **kwargs): | ||
self.request = kwargs.pop("request", None) | ||
super().__init__(*args, **kwargs) | ||
|
||
def clean_email(self): | ||
email = self.cleaned_data.get("email") | ||
self.user = User.objects.filter(email__iexact=email).first() | ||
if self.user is None: | ||
messages.error( | ||
self.request, | ||
format_error_modal_content( | ||
mark_safe( | ||
"<p>Cette adresse e-mail est inconnue de nos services.</p>" | ||
"<p>Si vous êtes déjà inscrit(e), " | ||
"assurez-vous de saisir correctement votre adresse e-mail.</p>" | ||
"<p>Si vous n'êtes pas encore inscrit(e), " | ||
"nous vous invitons à cliquer sur Inscription pour créer votre compte.</p>" | ||
), | ||
reverse("signup:job_seeker_situation"), | ||
"Inscription", | ||
), | ||
extra_tags="modal login_failure email_does_not_exist", | ||
) | ||
raise ValidationError("Cette adresse e-mail est inconnue. Veuillez soumettre une autre, ou vous inscrire.") | ||
return email | ||
|
||
|
||
class ItouLoginForm(LoginForm): | ||
# Hidden field allowing demo prescribers and employers to log in using the banner form | ||
demo_banner_account = forms.BooleanField(widget=forms.HiddenInput(), required=False) | ||
|
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 |
---|---|---|
|
@@ -208,19 +208,36 @@ def test_login(self, client): | |
assertRedirects(response, reverse("account_email_verification_sent")) | ||
|
||
|
||
class TestJopbSeekerLogin: | ||
def test_login(self, client): | ||
class TestJobSeekerPreLogin: | ||
def test_pre_login_email_invalid(self, client): | ||
form_data = {"email": "emailinvalid"} | ||
response = client.post(reverse("login:job_seeker"), data=form_data) | ||
assert response.status_code == 200 | ||
assert response.context["form"].errors["email"] == ["Saisissez une adresse e-mail valide."] | ||
|
||
def test_pre_login_redirects_to_existing_user(self, client): | ||
user = JobSeekerFactory() | ||
url = reverse("login:job_seeker") | ||
response = client.get(url) | ||
assert response.status_code == 200 | ||
|
||
form_data = { | ||
"login": user.email, | ||
"password": DEFAULT_PASSWORD, | ||
} | ||
form_data = {"email": user.email} | ||
response = client.post(url, data=form_data) | ||
assertRedirects(response, reverse("account_email_verification_sent")) | ||
assertRedirects(response, f'{reverse("login:existing_user", args=(user.public_id,))}?back_url={url}') | ||
|
||
def test_pre_login_email_unknown(self, client, snapshot): | ||
url = reverse("login:job_seeker") | ||
response = client.get(url) | ||
|
||
form_data = {"email": "[email protected]"} | ||
response = client.post(url, data=form_data) | ||
assert response.status_code == 200 | ||
|
||
assert response.context["form"].errors["email"] == [ | ||
"Cette adresse e-mail est inconnue. Veuillez soumettre une autre, ou vous inscrire." | ||
] | ||
assertMessages(response, [messages.Message(messages.ERROR, snapshot)]) | ||
assertContains(response, reverse("signup:job_seeker_situation")) | ||
|
||
@respx.mock | ||
@override_settings( | ||
|
@@ -290,6 +307,19 @@ def test_login(self, client, snapshot, identity_provider): | |
assertNotContains(response, self.UNSUPPORTED_IDENTITY_PROVIDER_TEXT) | ||
assert str(parse_response_to_soup(response, selector=".c-form")) == snapshot | ||
|
||
def test_login_django(self, client): | ||
user = JobSeekerFactory(identity_provider=IdentityProvider.DJANGO) | ||
url = reverse("login:existing_user", args=(user.public_id,)) | ||
response = client.get(url) | ||
assert response.status_code == 200 | ||
|
||
form_data = { | ||
"login": user.email, | ||
"password": DEFAULT_PASSWORD, | ||
} | ||
response = client.post(url, data=form_data) | ||
assertRedirects(response, reverse("account_email_verification_sent")) | ||
|
||
@pytest.mark.parametrize( | ||
"identity_provider", | ||
[ | ||
|
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