Anonymous avatar Anonymous committed a4babb2

Experimental support for social login.

Comments (0)

Files changed (6)

transifex/settings/40-apps.conf

 # django-userena
 AUTH_PROFILE_MODULE = 'txcommon.profile'
 USERENA_DEFAULT_PRIVACY = 'open'                # open, registered or closed
-LOGIN_REDIRECT_URL = '/accounts/%(username)s/'
+LOGIN_REDIRECT_URL = '/'
 LOGIN_URL = '/accounts/signin/'
 LOGOUT_URL = '/accounts/signout/'
 

transifex/settings/50-project.conf

     "django.contrib.messages.context_processors.messages",
     "notification.context_processors.notification",
     "staticfiles.context_processors.static_url",
+    "social_auth.context_processors.social_auth_backends",
 ]
 
 TEMPLATE_CONTEXT_PROCESSORS += (
     'staticfiles',
     'authority',
     'haystack',
+    'social_auth',
     'userena',
     'guardian',
     'easy_thumbnails',
 ]
 
 COMMENTS_APP = 'threadedcomments'
-
-
-AUTHENTICATION_BACKENDS = (
-    'userena.backends.UserenaAuthenticationBackend',
-    'guardian.backends.ObjectPermissionBackend',
-    'django.contrib.auth.backends.ModelBackend',
-)

transifex/settings/52-auth.conf

+AUTHENTICATION_BACKENDS = (
+    'userena.backends.UserenaAuthenticationBackend',
+    'guardian.backends.ObjectPermissionBackend',
+    'social_auth.backends.twitter.TwitterBackend',
+    'social_auth.backends.google.GoogleOAuth2Backend',
+    'social_auth.backends.google.GoogleBackend',
+    'social_auth.backends.facebook.FacebookBackend',
+    'django.contrib.auth.backends.ModelBackend',
+)
+
+USE_SOCIAL_LOGIN = True
+
+SOCIAL_AUTH_ENABLED_BACKENDS = ('twitter', 'google', 'facebook',)
+
+# This can be used to add custom authentication backends living
+# outside the django-social-auth app.
+SOCIAL_AUTH_IMPORT_BACKENDS = ()
+
+# Configured from https://dev.twitter.com/apps
+# Twitter does not allow local addresses inside the callback URL
+# so just a URL shortener that redirects to localhost during development.
+TWITTER_CONSUMER_KEY         = ''
+TWITTER_CONSUMER_SECRET      = ''
+
+# Configured from https://code.google.com/apis/console/.
+GOOGLE_OAUTH2_CLIENT_KEY     = ''
+GOOGLE_OAUTH2_CLIENT_SECRET  = ''
+GOOGLE_DISPLAY_NAME          = 'Transifex'
+
+FACEBOOK_APP_ID              = ''
+FACEBOOK_API_SECRET          = ''
+

transifex/templates/userena/profile_detail.html

     {% endif %}
   </div>
 </div>
+
+<div>
+{% if social_auth.associated %}
+  <h3>Associated social accounts</h3>
+  <ul>
+    {% for account in social_auth.associated %}
+      <li>
+        <span class="disconnect">
+          <a href={% url socialauth_disconnect_individual account.provider account.id %}>{{ account.provider|title }} (ID {{ account.id }})</a>
+        </span>
+    </li>
+    {% endfor %}
+  </ul>
+{% endif %}
+
+<h3>Associate new social account</h3>
+  <ul>
+  {% for name in social_auth.not_associated %}
+    <li><a rel="nofollow" href="{% url socialauth_associate_begin name %}">{{ name|title }}</a></li>
+  {% endfor %}
+  </ul>
+</div>
 {% endblock %}

transifex/templates/userena/signin_form.html

   <p class="forgot-password"><a href="{% url userena_signup %}" title="{% trans "Sigh up now!" %}">{% trans "You don't have an account?" %}</a></p>
   {% if next %}<input type="hidden" name="next" value="{{ next }}" />{% endif %}
 </form>
+
+<h3>Or sign in with</h3>
+<ul>
+  <li><a href="{% url socialauth_begin 'twitter' %}">Twitter</a></li>
+  <li><a href="{% url socialauth_begin 'google' %}">Google</a></li>
+  <li><a href="{% url socialauth_begin 'facebook' %}">Facebook</a></li>
+</ul>
 {% endblock %}

transifex/urls.py

         url(r'^accounts/', include('userena.urls')),
     )
 
+if settings.USE_SOCIAL_LOGIN:
+    urlpatterns += patterns('',
+        url(r'^accounts/', include('social_auth.urls')),
+    )
+
 if settings.ENABLE_NOTICES:
     urlpatterns += patterns('',
         (r'^notices/', include('notification.urls')),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.