@@ -0,0 +1,1935 @@
+# -*- coding: utf-8 -*-%0Afrom django.conf import settings%0Afrom django.contrib import messages%0Afrom django.shortcuts import redirect%0A%0Afrom social.exceptions import SocialAuthBaseException%0A%0A%0Aclass SocialAuthExceptionMiddleware(object):%0A    %22%22%22Middleware that handles Social Auth AuthExceptions by providing the user%0A    with a message, logging an error, and redirecting to some next location.%0A%0A    By default, the exception message itself is sent to the user and they are%0A    redirected to the location specified in the SOCIAL_AUTH_LOGIN_ERROR_URL%0A    setting.%0A%0A    This middleware can be extended by overriding the get_message or%0A    get_redirect_uri methods, which each accept request and exception.%0A    %22%22%22%0A    def process_exception(self, request, exception):%0A        self.strategy = getattr(request, 'strategy', None)%0A        if self.strategy is None or self.raise_exception(request, exception):%0A            return%0A%0A        if isinstance(exception, SocialAuthBaseException):%0A            backend_name = self.strategy.backend.name%0A            message = self.get_message(request, exception)%0A            url = self.get_redirect_uri(request, exception)%0A%0A            if request.user.is_authenticated():%0A                # Ensure that messages are added to authenticated users only,%0A                # otherwise this fails%0A                messages.error(request, message,%0A                               extra_tags=u'social-auth ' + backend_name)%0A            else:%0A                url += ('?' in url and '&' or '?') + %5C%0A                       'message=%25s&backend=%25s' %25 (message, backend_name)%0A            return redirect(url)%0A%0A    def raise_exception(self, request, exception):%0A        return self.strategy.setting('RAISE_EXCEPTIONS') or settings.DEBUG%0A%0A    def get_message(self, request, exception):%0A        return unicode(exception)%0A%0A    def get_redirect_uri(self, request, exception):%0A        return self.strategy.setting('LOGIN_ERROR_URL')%0A

Add django middleware