Skip to content

Instantly share code, notes, and snippets.

@votaguz
Last active December 19, 2015 18:48
Show Gist options
  • Save votaguz/6000847 to your computer and use it in GitHub Desktop.
Save votaguz/6000847 to your computer and use it in GitHub Desktop.
from django.shortcuts import redirect
from social_auth.middleware import SocialAuthExceptionMiddleware
from social_auth.exceptions import AuthAlreadyAssociated
class CustomSocialAuthExceptionMiddleware(SocialAuthExceptionMiddleware):
def get_redirect_uri(self, request, exception):
if isinstance(exception, AuthAlreadyAssociated):
# Redirect this error to a custom page where the situation is
# explained to users
return redirect('/account-already-associated')
else:
return super(CustomSocialAuthExceptionMiddleware, self)\
.get_redirect_uri(request, exception)
# Register it on settings.MIDDLEWARE_CLASSES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment