Skip to content

Commit

Permalink
Merge pull request #497 from MTES-MCT/user_accounts
Browse files Browse the repository at this point in the history
Gestion des comptes GUH
  • Loading branch information
thibault authored Jan 24, 2025
2 parents 19b3911 + 958d875 commit 8fac367
Show file tree
Hide file tree
Showing 61 changed files with 1,254 additions and 251 deletions.
7 changes: 6 additions & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#authentication-backends
AUTHENTICATION_BACKENDS = [
"django.contrib.auth.backends.ModelBackend",
"envergo.users.backends.AuthBackend",
]
# https://docs.djangoproject.com/en/dev/ref/settings/#auth-user-model
AUTH_USER_MODEL = "users.User"
Expand Down Expand Up @@ -430,3 +430,8 @@
"BREVO_NEWSLETTER_DOUBLE_OPT_IN_TEMPLATE_ID", default=None
),
}

SITE_FROM_EMAIL = {
"amenagement": "[email protected]",
"haie": "[email protected]",
}
10 changes: 10 additions & 0 deletions config/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@
DEFAULT_FROM_EMAIL = env(
"DJANGO_DEFAULT_FROM_EMAIL", default="EnvErgo <[email protected]>"
)
SITE_FROM_EMAIL = {
"amenagement": env(
"DJANGO_AMENAGEMENT_FROM_EMAIL",
default="EnvErgo <[email protected]>",
),
"haie": env(
"DJANGO_HAIE_FROM_EMAIL",
default="Guichet unique de la haie <[email protected]>",
),
}
# https://docs.djangoproject.com/en/dev/ref/settings/#server-email
SERVER_EMAIL = env("DJANGO_SERVER_EMAIL", default=DEFAULT_FROM_EMAIL)
# https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix
Expand Down
45 changes: 0 additions & 45 deletions config/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.contrib.auth.forms import SetPasswordForm
from django.urls import include, path
from django.utils.translation import gettext_lazy as _
from django.views import defaults as default_views
Expand All @@ -14,51 +12,8 @@
# customize error pages to handle multi-site
handler500 = server_error

# We redefine django auth patterns for better customization
auth_patterns = [
path(_("login/"), auth_views.LoginView.as_view(), name="login"),
path(_("logout/"), auth_views.LogoutView.as_view(), name="logout"),
path(
_("password_change/"),
auth_views.PasswordChangeView.as_view(form_class=SetPasswordForm),
name="password_change",
),
path(
_("password_change/done/"),
auth_views.PasswordChangeDoneView.as_view(),
name="password_change_done",
),
path(
_("password_reset/"),
auth_views.PasswordResetView.as_view(
subject_template_name="emails/password_reset_subject.txt",
email_template_name="emails/password_reset.txt",
html_email_template_name="emails/password_reset.html",
),
name="password_reset",
),
path(
_("password_reset/done/"),
auth_views.PasswordResetDoneView.as_view(),
name="password_reset_done",
),
path(
_("reset/<uidb64>/<token>/"),
auth_views.PasswordResetConfirmView.as_view(),
name="password_reset_confirm",
),
path(
_("reset/done/"),
auth_views.PasswordResetCompleteView.as_view(),
name="password_reset_complete",
),
]


urlpatterns = [
path("anymail/", include("anymail.urls")),
path(_("accounts/"), include(auth_patterns)),
path(_("users/"), include("envergo.users.urls")),
path(_("analytics/"), include("envergo.analytics.urls")),
path(_("feedback/"), include("envergo.analytics.urls")),
path("urlmappings/", include("envergo.urlmappings.urls")),
Expand Down
69 changes: 69 additions & 0 deletions config/urls_amenagement.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.contrib.auth import views as auth_views
from django.contrib.auth.forms import SetPasswordForm
from django.urls import include, path
from django.utils.translation import gettext_lazy as _

Expand All @@ -8,8 +10,75 @@

from .urls import urlpatterns as common_urlpatterns

# We redefine django auth patterns for better customization
auth_patterns = [
path(
_("login/"),
auth_views.LoginView.as_view(
template_name="amenagement/registration/login.html"
),
name="login",
),
path(
_("logout/"),
auth_views.LogoutView.as_view(
template_name="amenagement/registration/logged_out.html"
),
name="logout",
),
path(
_("password_change/"),
auth_views.PasswordChangeView.as_view(
form_class=SetPasswordForm,
template_name="amenagement/registration/password_change_form.html",
),
name="password_change",
),
path(
_("password_change/done/"),
auth_views.PasswordChangeDoneView.as_view(
template_name="registration/password_change_done.html"
),
name="password_change_done",
),
path(
_("password_reset/"),
auth_views.PasswordResetView.as_view(
template_name="amenagement/registration/password_reset_form.html",
subject_template_name="amenagement/emails/password_reset_subject.txt",
email_template_name="amenagement/emails/password_reset.txt",
html_email_template_name="amenagement/emails/password_reset.html",
),
name="password_reset",
),
path(
_("password_reset/done/"),
auth_views.PasswordResetDoneView.as_view(
template_name="amenagement/registration/password_reset_done.html",
),
name="password_reset_done",
),
path(
_("reset/<uidb64>/<token>/"),
auth_views.PasswordResetConfirmView.as_view(
template_name="amenagement/registration/password_reset_confirm.html"
),
name="password_reset_confirm",
),
path(
_("reset/done/"),
auth_views.PasswordResetCompleteView.as_view(
template_name="amenagement/registration/password_reset_complete.html"
),
name="password_reset_complete",
),
]


urlpatterns = [
path("", include("envergo.pages.urls_amenagement")),
path(_("accounts/"), include(auth_patterns)),
path(_("users/"), include("envergo.users.urls")),
path(
"a/<slug:reference>/",
ShortUrlAdminRedirectView.as_view(),
Expand Down
86 changes: 86 additions & 0 deletions config/urls_haie.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,98 @@
from django.contrib.auth import views as auth_views
from django.contrib.auth.forms import SetPasswordForm
from django.urls import include, path
from django.utils.translation import gettext_lazy as _

from config.urls import handler500 # noqa
from envergo.users.views import ActivateAccount, Register, RegisterSuccess

from .urls import urlpatterns as common_urlpatterns

# We redefine django auth patterns for better customization
auth_patterns = [
path(
_("login/"),
auth_views.LoginView.as_view(template_name="haie/registration/login.html"),
name="login",
),
path(
_("logout/"),
auth_views.LogoutView.as_view(
template_name="haie/registration/logged_out.html"
),
name="logout",
),
path(
_("password_change/"),
auth_views.PasswordChangeView.as_view(
form_class=SetPasswordForm,
template_name="haie/registration/password_change_form.html",
),
name="password_change",
),
path(
_("password_change/done/"),
auth_views.PasswordChangeDoneView.as_view(
template_name="registration/password_change_done.html"
),
name="password_change_done",
),
path(
_("password_reset/"),
auth_views.PasswordResetView.as_view(
template_name="haie/registration/password_reset_form.html",
subject_template_name="haie/emails/password_reset_subject.txt",
email_template_name="haie/emails/password_reset.txt",
html_email_template_name="haie/emails/password_reset.html",
),
name="password_reset",
),
path(
_("password_reset/done/"),
auth_views.PasswordResetDoneView.as_view(
template_name="haie/registration/password_reset_done.html",
),
name="password_reset_done",
),
path(
_("reset/<uidb64>/<token>/"),
auth_views.PasswordResetConfirmView.as_view(
template_name="haie/registration/password_reset_confirm.html"
),
name="password_reset_confirm",
),
path(
_("reset/done/"),
auth_views.PasswordResetCompleteView.as_view(
template_name="haie/registration/password_reset_complete.html"
),
name="password_reset_complete",
),
path(
_("register/"),
Register.as_view(template_name="haie/registration/register.html"),
name="register",
),
path(
_("register-success/"),
RegisterSuccess.as_view(
template_name="haie/registration/register_success.html"
),
name="register_success",
),
path(
_("register/<uidb64>/<token>/"),
ActivateAccount.as_view(
template_name="haie/registration/activate_account.html"
),
name="activate_account",
),
]


urlpatterns = [
path("", include("envergo.pages.urls_haie")),
path(_("accounts/"), include(auth_patterns)),
path(_("moulinette/"), include("envergo.moulinette.urls_haie")),
path("haies/", include("envergo.hedges.urls")),
path("projet/", include("envergo.petitions.urls_haie")),
Expand Down
10 changes: 10 additions & 0 deletions envergo/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ def user() -> User:
return UserFactory()


@pytest.fixture
def amenagement_user() -> User:
return UserFactory(access_amenagement=True, access_haie=False)


@pytest.fixture
def haie_user() -> User:
return UserFactory(access_amenagement=False, access_haie=True)


@pytest.fixture
def admin_user() -> User:
return UserFactory(is_staff=True, is_superuser=True)
Expand Down
9 changes: 9 additions & 0 deletions envergo/templates/amenagement/emails/_email_signature.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<p>
À très bientôt,
<br />
L'équipe EnvErgo
<br />
07 56 81 02 11
<br />
<a href="https://envergo.beta.gouv.fr">https://envergo.beta.gouv.fr</a>
</p>
4 changes: 4 additions & 0 deletions envergo/templates/amenagement/emails/_email_signature.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
À très bientôt,
L'équipe EnvErgo
07 56 81 02 11
https://envergo.beta.gouv.fr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</p>

<p>
<a href="{{ full_login_url }}">Activez votre compte EnvErgo.</a>
<a href="{{ full_activate_url }}">Activez votre compte EnvErgo.</a>
</p>

<p>Si vous n'êtes pas à l'initiative de cette demande, merci de ne pas prendre cet e-mail en compte.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Vous venez de faire la demande d'une création d'espace personnalisé sur EnvErg

Il reste une étape pour l'activer. Pour ce faire, il vous suffit de cliquer sur le lien suivant :

{{ full_login_url }}
{{ full_activate_url }}

Si vous n'êtes pas à l'initiative de cette demande, merci de ne pas prendre cet e-mail en compte.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
<p>Veuillez vous rendre sur cette page pour vous connecter. Vous pourrez ensuite choisir un nouveau mot de passe.</p>

<p>
<a href="https://{{ domain }}{% url 'token_login' uidb64=uid token=token %}">
https://{{ domain }}{% url 'token_login' uidb64=uid token=token %}
<a href="https://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}">
https://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}
</a>
</p>

{% include 'emails/_email_signature.html' %}
{% include 'amenagement/emails/_email_signature.html' %}

{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Vous recevez ce message car vous avez demandé la réinitiatisation de votre mot

Veuillez vous rendre sur cette page pour vous connecter. Vous pourrez ensuite choisir un nouveau mot de passe.

https://{{ domain }}{% url 'token_login' uidb64=uid token=token %}
https://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}

{% include 'emails/_email_signature.txt' %}
{% include 'amenagement/emails/_email_signature.txt' %}
14 changes: 14 additions & 0 deletions envergo/templates/amenagement/registration/activate_account.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends 'base.html' %}

{% block title %}Votre identité est confirmée{% endblock %}

{% block article %}
<h1>Votre identité est confirmée</h1>

<p class="lead">Votre compte est désormais actif.</p>

<p>
<a href="{% url 'login' %}">Vous pouvez vous connecter.</a>
</p>

{% endblock %}
Loading

0 comments on commit 8fac367

Please sign in to comment.