]> git.parisson.com Git - django-social-auth.git/commitdiff
User-friendly errors, russian translation
authorAndrii Kostenko <andrey@kostenko.name>
Thu, 16 Feb 2012 18:21:07 +0000 (22:21 +0400)
committerAndrii Kostenko <andrey@kostenko.name>
Thu, 16 Feb 2012 18:21:07 +0000 (22:21 +0400)
setup.py
social_auth/backends/__init__.py
social_auth/locale/ru/LC_MESSAGES/django.mo [new file with mode: 0644]
social_auth/locale/ru/LC_MESSAGES/django.po [new file with mode: 0644]
social_auth/utils.py
social_auth/views.py

index 171c7aee088002b001ec4f2983abc6b0279c4771..83a0de30a7c726fb0c9cf9c3142d3c44105fb44c 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -36,6 +36,7 @@ setup(name='django-social-auth',
                 'social_auth.backends',
                 'social_auth.backends.contrib',
                 'social_auth.backends.pipeline'],
+      package_data={'social_auth':['locale/*/LC_MESSAGES/*']},
       long_description=long_description(),
       install_requires=['oauth2>=1.5.167',
                         'python_openid>=2.2'],
index 30e84efb997e3e2367b0173fd3f7a0727077b047..0b06d371ea1c0cd385e28de0969f6a0e0dca99a9 100644 (file)
@@ -12,6 +12,7 @@ enabled.
 from urllib2 import Request, urlopen
 from urllib import urlencode
 from urlparse import urlsplit
+from django.utils.translation import ugettext
 
 from openid.consumer.consumer import Consumer, SUCCESS, CANCEL, FAILURE
 from openid.consumer.discover import DiscoveryFailure
@@ -26,7 +27,7 @@ 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
+from social_auth.utils import setting, log, model_to_ctype, ctype_to_model, DSAException
 from social_auth.store import DjangoOpenIDStore
 from social_auth.backends.exceptions import StopPipeline
 
@@ -629,8 +630,10 @@ class BaseOAuth2(BaseOAuth):
     def auth_complete(self, *args, **kwargs):
         """Completes loging process, must return user instance"""
         if self.data.get('error'):
-            error = self.data.get('error_description') or self.data['error']
-            raise ValueError('OAuth2 authentication failed: %s' % error)
+            if self.data['error'] == 'access_denied':
+                raise DSAException(ugettext(u'Authentication process was cancelled'))
+            error = self.data.get('error_description') or self.data.get('error')
+            raise DSAException(ugettext(u'Authentication failed: %s') % error)
 
         client_id, client_secret = self.get_key_and_secret()
         params = {'grant_type': 'authorization_code',  # request auth code
@@ -648,8 +651,10 @@ class BaseOAuth2(BaseOAuth):
             raise ValueError('Unknown OAuth2 response type')
 
         if response.get('error'):
+            if response.get('error') == 'access_denied':
+                raise DSAException(ugettext(u'Authentication process was cancelled'))
             error = response.get('error_description') or response.get('error')
-            raise ValueError('OAuth2 authentication failed: %s' % error)
+            raise DSAException(ugettext(u'Authentication failed: %s') % error)
         else:
             response.update(self.user_data(response['access_token']) or {})
             kwargs.update({
diff --git a/social_auth/locale/ru/LC_MESSAGES/django.mo b/social_auth/locale/ru/LC_MESSAGES/django.mo
new file mode 100644 (file)
index 0000000..9d0cc9c
Binary files /dev/null and b/social_auth/locale/ru/LC_MESSAGES/django.mo differ
diff --git a/social_auth/locale/ru/LC_MESSAGES/django.po b/social_auth/locale/ru/LC_MESSAGES/django.po
new file mode 100644 (file)
index 0000000..1a62569
--- /dev/null
@@ -0,0 +1,37 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-02-16 21:41+0400\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"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"
+
+#: build/lib/social_auth/views.py:70 social_auth/views.py:70
+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
+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
+#, python-format
+msgid "Authentication failed: %s"
+msgstr "Ошибка аутентификации: %s"
index 9f288ed89c96e36564bbc2e72e46d956524cd749..4a0601a83cf1f0453b7300262892b0a997b9abbc 100644 (file)
@@ -1,3 +1,4 @@
+# coding=utf-8
 import urlparse
 import logging
 from collections import defaultdict
@@ -6,6 +7,13 @@ 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):
     """
index 45140ee95621e928252eff691c26600c40ac6a47..6caeaebd93a5f61528d8cd046b7a6dc7b9601981 100644 (file)
@@ -13,10 +13,11 @@ from django.core.urlresolvers import reverse
 from django.contrib.auth import login, REDIRECT_FIELD_NAME
 from django.contrib.auth.decorators import login_required
 from django.contrib import messages
+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
+from social_auth.utils import sanitize_redirect, setting, log, DSAException
 
 
 DEFAULT_REDIRECT = setting('SOCIAL_AUTH_LOGIN_REDIRECT_URL') or \
@@ -46,6 +47,16 @@ def dsa_view(redirect_name=None):
 
             try:
                 return func(request, backend, *args, **kwargs)
+            except DSAException, 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
@@ -56,7 +67,7 @@ def dsa_view(redirect_name=None):
 
                 if 'django.contrib.messages' in setting('INSTALLED_APPS'):
                     from django.contrib.messages.api import error
-                    error(request, unicode(e), extra_tags=backend_name)
+                    error(request, ugettext(u'Unknown authentication error. Try again later.'), extra_tags=backend_name)
                 else:
                     log('warn', 'Messages framework not in place, some '+
                                 'errors have not been shown to the user.')