diff --git a/opentech/apply/users/middleware.py b/opentech/apply/users/middleware.py new file mode 100644 index 0000000000000000000000000000000000000000..15cd712a5e7dcb1ce96423e687e810201f11bd4c --- /dev/null +++ b/opentech/apply/users/middleware.py @@ -0,0 +1,12 @@ +from social_core.exceptions import AuthForbidden +from social_django.middleware import SocialAuthExceptionMiddleware as _SocialAuthExceptionMiddleware + +class SocialAuthExceptionMiddleware(_SocialAuthExceptionMiddleware): + """ + Wrapper around SocialAuthExceptionMiddleware to customise messages + """ + def get_message(self, request, exception): + if isinstance(exception, AuthForbidden): + return 'Your credentials are not allowed' + + super().get_message(request, exception) \ No newline at end of file diff --git a/opentech/settings/base.py b/opentech/settings/base.py index 38c958902a2f43a3babbbe31749555e0dba3f657..38fddcc68a3bd5bb43b3ad2909cc3abd6f296af1 100644 --- a/opentech/settings/base.py +++ b/opentech/settings/base.py @@ -75,7 +75,7 @@ MIDDLEWARE = [ 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'social_django.middleware.SocialAuthExceptionMiddleware', + 'opentech.apply.users.middleware.SocialAuthExceptionMiddleware', 'wagtail.wagtailcore.middleware.SiteMiddleware', 'wagtail.wagtailredirects.middleware.RedirectMiddleware',