From 0122bf7439be17d8d82c2137d534535685d6261b Mon Sep 17 00:00:00 2001
From: Dan Braghis <dan.braghis@torchbox.com>
Date: Wed, 24 Jan 2018 10:45:19 +0000
Subject: [PATCH] Customise the social auth AuthForbidden message

---
 opentech/apply/users/middleware.py | 12 ++++++++++++
 opentech/settings/base.py          |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 opentech/apply/users/middleware.py

diff --git a/opentech/apply/users/middleware.py b/opentech/apply/users/middleware.py
new file mode 100644
index 000000000..15cd712a5
--- /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 38c958902..38fddcc68 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',
-- 
GitLab