From e13c36ab74c796a3051bcbd07043bc5384ddbda4 Mon Sep 17 00:00:00 2001 From: Andrii Kostenko Date: Fri, 17 Feb 2012 15:41:04 +0400 Subject: [PATCH] Account already in use exception Moved exception class to exceptions.py module --- social_auth/backends/__init__.py | 3 ++- social_auth/backends/exceptions.py | 10 ++++++++++ social_auth/backends/pipeline/social.py | 6 +++++- social_auth/locale/ru/LC_MESSAGES/django.mo | Bin 877 -> 1013 bytes social_auth/locale/ru/LC_MESSAGES/django.po | 21 ++++++++++---------- social_auth/tests/facebook.py | 1 + social_auth/utils.py | 7 ------- social_auth/views.py | 3 ++- 8 files changed, 31 insertions(+), 20 deletions(-) diff --git a/social_auth/backends/__init__.py b/social_auth/backends/__init__.py index 0b06d37..ea99c1e 100644 --- a/social_auth/backends/__init__.py +++ b/social_auth/backends/__init__.py @@ -27,7 +27,8 @@ from django.contrib.auth.backends import ModelBackend from django.utils import simplejson from django.utils.importlib import import_module -from social_auth.utils import setting, log, model_to_ctype, ctype_to_model, DSAException +from social_auth.utils import setting, log, model_to_ctype, ctype_to_model +from social_auth.backends.exceptions import DSAException from social_auth.store import DjangoOpenIDStore from social_auth.backends.exceptions import StopPipeline diff --git a/social_auth/backends/exceptions.py b/social_auth/backends/exceptions.py index 8518b31..c0e52cb 100644 --- a/social_auth/backends/exceptions.py +++ b/social_auth/backends/exceptions.py @@ -1,5 +1,15 @@ +# coding=utf-8 + class StopPipeline(Exception): """Stop pipeline process exception. Raise this exception to stop the rest of the pipeline process. """ pass + + +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 \ No newline at end of file diff --git a/social_auth/backends/pipeline/social.py b/social_auth/backends/pipeline/social.py index d843616..02c085f 100644 --- a/social_auth/backends/pipeline/social.py +++ b/social_auth/backends/pipeline/social.py @@ -1,8 +1,10 @@ from django.db.utils import IntegrityError +from django.utils.translation import ugettext 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 def social_auth_user(backend, uid, user=None, *args, **kwargs): @@ -20,7 +22,9 @@ def social_auth_user(backend, uid, user=None, *args, **kwargs): if social_user: if user and social_user.user != user: - raise ValueError('Account already in use.', social_user) + raise DSAException(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 --git a/social_auth/locale/ru/LC_MESSAGES/django.mo b/social_auth/locale/ru/LC_MESSAGES/django.mo index 9d0cc9cd89afc38d2c0b0f16294668bd6b62097f..7cf315be43b13e7264b59fee9e3f2aa42d74b0c1 100644 GIT binary patch delta 273 zcmaFM_LaT7I%|ex zWELx^Y7`XZmu04;7HJkMBqk^4m*$lyB<2*QCZ<#>WacT97N_b>T;I-au3%_tWn{Y9 zmhl9m%i4=g7xrCjQn;|;!Y&}(aIyKqULY66ETGu73tJT~?6}x?VgH4F7j|Flxv(85 RxblsflPVQyS000O%85sZo diff --git a/social_auth/locale/ru/LC_MESSAGES/django.po b/social_auth/locale/ru/LC_MESSAGES/django.po index 1a62569..a810bb3 100644 --- a/social_auth/locale/ru/LC_MESSAGES/django.po +++ b/social_auth/locale/ru/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-02-16 21:41+0400\n" +"POT-Creation-Date: 2012-02-17 15:25+0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -16,22 +16,23 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%" -"10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)\n" -#: build/lib/social_auth/views.py:70 social_auth/views.py:70 +#: views.py:71 msgid "Unknown authentication error. Try again later." msgstr "Непредвиденная ошибка аутентификации. Попробуйте позже." -#: build/lib/social_auth/backends/__init__.py:634 -#: build/lib/social_auth/backends/__init__.py:655 -#: social_auth/backends/__init__.py:634 social_auth/backends/__init__.py:655 +#: backends/__init__.py:635 backends/__init__.py:656 msgid "Authentication process was cancelled" msgstr "Процесс аутентификации был прерван" -#: build/lib/social_auth/backends/__init__.py:636 -#: build/lib/social_auth/backends/__init__.py:657 -#: social_auth/backends/__init__.py:636 social_auth/backends/__init__.py:657 +#: backends/__init__.py:637 backends/__init__.py:658 #, python-format msgid "Authentication failed: %s" msgstr "Ошибка аутентификации: %s" + +#: backends/pipeline/social.py:25 +#, python-format +msgid "This %(provider)s account already in use." +msgstr "Этот аккаунт %(provider)s уже используется." diff --git a/social_auth/tests/facebook.py b/social_auth/tests/facebook.py index 74d5b47..444343b 100644 --- a/social_auth/tests/facebook.py +++ b/social_auth/tests/facebook.py @@ -58,6 +58,7 @@ class FacebookTestLogin(FacebookTestCase): redirect_page = content url = REDIRECT_RE.findall(redirect_page) + print redirect_page self.assertTrue(url) # URL comes on JS scaped, needs to be clean first, any better way? url = url[0].replace('\u0025', '%').replace('\\', '') diff --git a/social_auth/utils.py b/social_auth/utils.py index 4a0601a..e53f680 100644 --- a/social_auth/utils.py +++ b/social_auth/utils.py @@ -7,13 +7,6 @@ from django.conf import settings from django.db.models import Model from django.contrib.contenttypes.models import ContentType -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 - def sanitize_log_data(secret, data=None, leave_characters=4): """ diff --git a/social_auth/views.py b/social_auth/views.py index 6caeaeb..ba99f94 100644 --- a/social_auth/views.py +++ b/social_auth/views.py @@ -17,7 +17,8 @@ from django.utils.translation import ugettext from django.views.decorators.csrf import csrf_exempt from social_auth.backends import get_backend -from social_auth.utils import sanitize_redirect, setting, log, DSAException +from social_auth.utils import sanitize_redirect, setting, log +from social_auth.backends.exceptions import DSAException DEFAULT_REDIRECT = setting('SOCIAL_AUTH_LOGIN_REDIRECT_URL') or \ -- 2.39.5