diff --git a/umap/middleware.py b/umap/middleware.py index ffe01ebf..5312c551 100644 --- a/umap/middleware.py +++ b/umap/middleware.py @@ -1,6 +1,12 @@ from django.conf import settings +from django.contrib import messages +from django.contrib.auth import BACKEND_SESSION_KEY from django.core.exceptions import MiddlewareNotUsed -from django.http import HttpResponseForbidden +from django.http import ( + HttpResponseForbidden, + HttpResponseRedirect, +) +from django.urls import reverse from django.utils.translation import gettext as _ @@ -15,3 +21,26 @@ def readonly_middleware(get_response): return get_response(request) return middleware + + +def deprecated_auth_backend(get_response): + def middleware(request): + backend = request.session.get(BACKEND_SESSION_KEY) + if backend in settings.DEPRECATED_AUTHENTICATION_BACKENDS: + name = backend.split(".")[-1] + messages.error( + request, + _( + "Using ā€œ%(name)sā€ to authenticate is deprecated and will be " + "removed soon. " + "Please configure another provider below before losing access " + "to your account and maps." + ) + % {"name": name}, + ) + if "/map/" in request.path: + return HttpResponseRedirect(reverse("user_profile")) + + return get_response(request) + + return middleware diff --git a/umap/settings/base.py b/umap/settings/base.py index 5d6c5930..ecb51326 100644 --- a/umap/settings/base.py +++ b/umap/settings/base.py @@ -235,6 +235,7 @@ MIDDLEWARE = ( "django.middleware.csrf.CsrfViewMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", + "umap.middleware.deprecated_auth_backend", ) diff --git a/umap/static/umap/img/providers/twitter-oauth2.png b/umap/static/umap/img/providers/twitter-oauth2.png index b263eac1..93a90fc3 100644 Binary files a/umap/static/umap/img/providers/twitter-oauth2.png and b/umap/static/umap/img/providers/twitter-oauth2.png differ diff --git a/umap/templates/auth/user_form.html b/umap/templates/auth/user_form.html index 3ffe9852..6870e4db 100644 --- a/umap/templates/auth/user_form.html +++ b/umap/templates/auth/user_form.html @@ -29,9 +29,9 @@

{% trans "Your current providers" %}

-