From: Stas Kravets Date: Fri, 9 Mar 2012 11:55:29 +0000 (+0400) Subject: Merge remote-tracking branch 'origin/master' X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=3e95b2abf0114f34f26ffc3f124f88e60ef89deb;p=django-social-auth.git Merge remote-tracking branch 'origin/master' Conflicts: social_auth/backends/__init__.py social_auth/backends/exceptions.py social_auth/backends/facebook.py social_auth/backends/pipeline/social.py social_auth/views.py --- 3e95b2abf0114f34f26ffc3f124f88e60ef89deb diff --cc social_auth/backends/exceptions.py index 0e8b73a,c0e52cb..f711736 --- a/social_auth/backends/exceptions.py +++ b/social_auth/backends/exceptions.py @@@ -1,55 -1,15 +1,60 @@@ -# coding=utf-8 ++from django.utils.translation import ugettext + -class StopPipeline(Exception): +class SocialAuthBaseException(ValueError): + """Base class for pipeline exceptions.""" + pass + + +class StopPipeline(SocialAuthBaseException): """Stop pipeline process exception. Raise this exception to stop the rest of the pipeline process. """ - pass + def __unicode__(self): + return u'Stop pipeline' -class DSAException(ValueError): - """ - django-social-auth exception. This exception can be showed to user. It is thrown in normal situations – user declined - access, access token expired, etc. - """ - pass +class AuthException(SocialAuthBaseException): + """Auth process exception.""" + def __init__(self, backend, *args, **kwargs): + self.backend = backend + super(AuthException, self).__init__(*args, **kwargs) + + +class AuthFailed(AuthException): + """Auth process failed for some reason.""" + def __unicode__(self): - msg = super(AuthFailed, self).__unicode__() - return u'Authentication process failed %s' % msg ++ ++ if self.message == 'access_denied': ++ return ugettext(u'Authentication process was cancelled') ++ else: ++ return ugettext(u'Authentication failed: %s') % super(AuthFailed, self).__unicode__() + + +class AuthCanceled(AuthException): + """Auth process was canceled by user.""" + def __unicode__(self): + return u'Authentication process canceled' + + +class AuthUnknownError(AuthException): + """Unknown auth process error.""" + def __unicode__(self): + msg = super(AuthFailed, self).__unicode__() + return u'An unknown error happened while authenticating %s' % msg + + +class AuthTokenError(AuthException): + """Auth token error.""" + def __unicode__(self): + msg = super(AuthFailed, self).__unicode__() + return u'Token error: %s' % msg + + +class AuthMissingParameter(AuthException): + """Missing parameter needed to start or complete the process.""" + def __init__(self, backend, parameter, *args, **kwargs): + self.parameter = parameter + super(AuthMissingParameter, self).__init__(backend, *args, **kwargs) + + def __unicode__(self): + return u'Missing needed parameter %s' % self.parameter diff --cc social_auth/backends/pipeline/social.py index 708b4de,02c085f..6d0e6cc --- a/social_auth/backends/pipeline/social.py +++ b/social_auth/backends/pipeline/social.py @@@ -3,7 -4,7 +3,8 @@@ from django.db.utils import IntegrityEr from social_auth.utils import setting from social_auth.models import UserSocialAuth from social_auth.backends.pipeline import warn_setting -from social_auth.backends.exceptions import DSAException +from social_auth.backends.exceptions import AuthException ++from django.utils.translation import ugettext def social_auth_user(backend, uid, user=None, *args, **kwargs): @@@ -21,7 -22,9 +22,9 @@@ if social_user: if user and social_user.user != user: - raise AuthException(backend, 'Account already in use.') - raise DSAException(ugettext('This %(provider)s account already in use.') % { ++ raise AuthException(backend, ugettext('This %(provider)s account already in use.') % { + 'provider':backend.name, + }) elif not user: user = social_user.user return {'social_user': social_user, 'user': user} diff --cc social_auth/views.py index ad92fa2,ba99f94..76366cf --- a/social_auth/views.py +++ b/social_auth/views.py @@@ -17,9 -17,9 +17,10 @@@ from django.utils.importlib import impo from django.views.decorators.csrf import csrf_exempt from social_auth.backends import get_backend -from social_auth.utils import sanitize_redirect, setting, log -from social_auth.backends.exceptions import DSAException +from social_auth.utils import sanitize_redirect, setting, log, \ + backend_setting, clean_partial_pipeline ++from social_auth.backends.exceptions import AuthFailed DEFAULT_REDIRECT = setting('SOCIAL_AUTH_LOGIN_REDIRECT_URL') or \ setting('LOGIN_REDIRECT_URL') @@@ -50,6 -48,16 +51,16 @@@ def dsa_view(redirect_name=None) try: return func(request, backend, *args, **kwargs) - except DSAException, e: ++ except AuthFailed, e: + backend_name = backend.AUTH_BACKEND.name + if 'django.contrib.messages' in setting('INSTALLED_APPS'): + from django.contrib.messages.api import error + error(request, unicode(e), extra_tags=backend_name) + else: + log('warn', 'Messages framework not in place, some '+ + 'errors have not been shown to the user.') + url = setting('SOCIAL_AUTH_BACKEND_ERROR_URL', LOGIN_ERROR_URL) + return HttpResponseRedirect(url) except Exception, e: # some error ocurred if RAISE_EXCEPTIONS: raise