]> git.parisson.com Git - django-social-auth.git/commitdiff
Merge remote-tracking branch 'origin/master'
authorStas Kravets <krvss@mail.ru>
Fri, 9 Mar 2012 11:55:29 +0000 (15:55 +0400)
committerStas Kravets <krvss@mail.ru>
Fri, 9 Mar 2012 11:55:29 +0000 (15:55 +0400)
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

1  2 
setup.py
social_auth/backends/exceptions.py
social_auth/backends/pipeline/social.py
social_auth/views.py

diff --cc setup.py
Simple merge
index 0e8b73a8af5c1031f53cfe83b8a9de12971e86e7,c0e52cba5e70aa1a4dacc57079e39b2a687ffab6..f7117369c0494fc07a70f04b85a4056cd8ba6aa1
@@@ -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
index 708b4de1792dc73bed0a89c928cb54cd7456c410,02c085fafb0fdc4927bb1357eb73b9d5299ea96a..6d0e6cce43ffc19bbe327f710d565a96147d63fe
@@@ -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}
index ad92fa26bf41e9c98a22e15ceaa68f938dafe2ed,ba99f94ec8e70a8c63b31e314cf34d9d0fc311d5..76366cf66c62dc29ee30ddca7b19032ebff48c26
@@@ -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