Просмотр исходного кода

Expose list of configured social auth providers to the UI

Rafał Pitoń 7 лет назад
Родитель
Сommit
6b789469ca

+ 10 - 0
docs/settings/Core.md

@@ -251,6 +251,16 @@ Items in Misago are usually indexed in search engine on save or update. If you c
 Path to function or callable used by Misago to generate slugs. Defaults to `misago.core.slugify.default`. Use this function if you want to customize slugs generation on your community.
 
 
+## `MISAGO_SOCIAL_AUTH_PROVIDERS_NAMES`
+
+This setting allows you to override social auth provider's name displayed in Misago interface to be more descriptive. For example, to rename "Facebook" to "Facebook Connect" and "Google Plus" to "Google+" at same time, add following code to your `settings.py`:
+
+    MISAGO_SOCIAL_AUTH_PROVIDERS_NAMES = {
+        'facebook': "Facebook Connect",
+        'google-plus': "Google+",
+    }
+
+
 ## `MISAGO_STOP_FORUM_SPAM_MIN_CONFIDENCE`
 
 Minimum confidence returned by [Stop Forum Spam](http://www.stopforumspam.com/) for Misago to reject new registration and block IP address for 1 day.

+ 10 - 0
frontend/style/flavor/social-buttons.less

@@ -0,0 +1,10 @@
+//
+// Social Buttons Flavor
+// --------------------------------------------------
+
+// Those buttons simply add brand color over the .btn-default
+.misago-social-btn(@color) {
+  &, &:disabled, &:disabled:hover, {
+    color: @color;
+  }
+}

+ 3 - 0
misago/conf/context_processors.py

@@ -2,6 +2,8 @@ from django.contrib.staticfiles.templatetags.staticfiles import static
 from django.urls import reverse
 from django.utils.translation import get_language
 
+from misago.users.social.utils import get_enabled_social_auth_sites_list
+
 from .gateway import settings as misago_settings  # noqa
 from .gateway import db_settings
 
@@ -30,6 +32,7 @@ def preload_settings_json(request):
         'LOGIN_REDIRECT_URL': reverse(misago_settings.LOGIN_REDIRECT_URL),
         'LOGIN_URL': reverse(misago_settings.LOGIN_URL),
         'LOGOUT_URL': reverse(misago_settings.LOGOUT_URL),
+        'SOCIAL_AUTH': get_enabled_social_auth_sites_list(),
     })
 
     request.frontend_context.update({

+ 6 - 0
misago/conf/defaults.py

@@ -129,6 +129,12 @@ MISAGO_USE_STOP_FORUM_SPAM = True
 MISAGO_STOP_FORUM_SPAM_MIN_CONFIDENCE = 80
 
 
+# Social Auth Providers Names Overrides
+# Allows you to customize 
+
+MISAGO_SOCIAL_AUTH_PROVIDERS_NAMES = {} 
+
+
 # Login API URL
 
 MISAGO_LOGIN_API_URL = 'auth'

+ 0 - 0
misago/users/social/__init__.py


+ 87 - 0
misago/users/social/providersnames.py

@@ -0,0 +1,87 @@
+"""
+Python Social Auth doesn't provide information about proper names for OAuth sites,
+so we are using this file for overrides whenever name is different than `provider.name.title`
+"""
+
+PROVIDERS_NAMES = {
+    'angel': "AngelList",
+    'aol': "AOL",
+    'arcgis': "ArcGIS",
+    'azuread-oauth2': "Azure Active Directory",
+    'azuread-b2c-oauth2': "Azure Active Directory B2C",
+    'azuread-tenant-oauth2': "Azure Active Directory tenant",
+    'battlenet-oauth2': "Blizzard Battle.net",
+    'belgiumeid': "Belgium EID",
+    'bitbucket-oauth2': "Bitbucket",
+    'bungie': "Bungie.net",
+    'chatwork': "ChatWork",
+    'classlink': "ClassLink",
+    'digitalocean': "DigitalOcean",
+    'douban-oauth2': "Douban",
+    'dropbox-oauth2': "Dropbox",
+    'echosign': "Adobe Sign",
+    'eveonline': "EVE Online",
+    'evernote-sandbox': "Evernote (sandbox)",
+    'facebook-app': "Facebook",
+    'google-appengine': "Google App Engine",
+    'github': "GitHub",
+    'github-org': "GitHub Organization",
+    'github-team': "GitHub Team",
+    'github-enterprise': "GitHub Enterprise",
+    'github-enterprise-org': "GitHub Enterprise Organization",
+    'github-enterprise-team': "GitHub Enterprise Team",
+    'gitlab': "GitLab",
+    'goclio': "Clio.com",
+    'goclioeu': "Clio.eu",
+    'google': "Google",
+    'google-oauth': "Google",
+    'google-oauth2': "Google",
+    'google-plus': "Google Plus",
+    'google-openidconnect': "Google",
+    'itembase-sandbox': "Itembase (sandbox)",
+    'justgiving': "JustGiving",
+    'khanacademy-oauth1': "Khan Academy",
+    'lastfm': "Last.fm",
+    'line': "LINE",
+    'linkedin': "LinkedIn",
+    'live': "Live Connect",
+    'livejournal': "LiveJournal",
+    'loginradius': "LoginRadius",
+    'mailchimp': "MailChimp",
+    'mailru-oauth2': "Mail.ru",
+    'mapmyfitness': "MapMyFitness",
+    'mediawiki': "MediaWiki",
+    'mendeley-oauth2': "Mendeley",
+    'microsoft-graph': "Microsoft",
+    'mineid': "MineID",
+    'nationbuilder': "NationBuilder",
+    'naver': "NAVER",
+    'actionid-openid': "NGP VAN ActionID",
+    'nk': "nk.pl",
+    'odnoklassniki-oauth2': "OK.RU",
+    'odnoklassniki-app': "OK.RU",
+    'openshift': "OpenShift",
+    'openstreetmap': "PpenStreetMap",
+    'orcid': "ORCID",
+    'professionali': "Professionali.ru",
+    'qq': "QQ",
+    'rdio-oauth1': "Pandora",
+    'rdio-oauth2': "Pandora",
+    'salesforce-oauth2': "Salesforce",
+    'salesforce-oauth2-sandbox': "Salesforce (sandbox)",
+    'saml': "SAML",
+    'shimmering': "Shimmering Verify",
+    'stackoverflow': "StackExchange",
+    'stocktwits': "StockTwits",
+    'opensuse': "Open SUSE OpenId",
+    'datagouv': "uData",
+    'vimeo-oauth2': "Vimeo",
+    'vk': "VK",
+    'weixinapp': "Weixin",
+    'yahoo-oauth': "Yahoo",
+    'yahoo-oauth2': "Yahoo",
+    'yammer-staging': "Yammer (staging)",
+    'yandex-openid': "Yandex",
+    'yandex-oauth2': "Yandex",
+    'yaru': "Yandex",
+}

+ 20 - 0
misago/users/social/utils.py

@@ -0,0 +1,20 @@
+from social_core.backends.utils import load_backends
+
+from misago.conf import settings
+
+from .providersnames import PROVIDERS_NAMES
+
+
+def get_enabled_social_auth_sites_list():
+    social_auth_backends = load_backends(settings.AUTHENTICATION_BACKENDS)
+    providers_list = []
+    for provider_id in social_auth_backends:
+        provider_name = settings.MISAGO_SOCIAL_AUTH_PROVIDERS_NAMES.get(provider_id)
+        if not provider_name:
+            provider_name = PROVIDERS_NAMES.get(provider_id, provider_id.title())
+            
+        providers_list.append({
+            'id': provider_id,
+            'name': provider_name,
+        })
+    return providers_list

+ 44 - 0
misago/users/tests/test_social_utils.py

@@ -0,0 +1,44 @@
+from django.test import TestCase, override_settings
+
+from misago.users.social.utils import get_enabled_social_auth_sites_list
+
+
+class SocialUtilsTests(TestCase):
+    @override_settings(AUTHENTICATION_BACKENDS=[
+        'misago.users.authbackends.MisagoBackend',
+        'social_core.backends.facebook.FacebookOAuth2',
+        'social_core.backends.github.GithubOAuth2',
+    ])
+    def test_get_enabled_social_auth_sites_list(self):
+        self.assertEqual(get_enabled_social_auth_sites_list(), [
+            {
+                'id': 'facebook',
+                'name': 'Facebook',
+            },
+            {
+                'id': 'github',
+                'name': 'GitHub',
+            }
+        ])
+
+    @override_settings(
+        AUTHENTICATION_BACKENDS=[
+            'misago.users.authbackends.MisagoBackend',
+            'social_core.backends.facebook.FacebookOAuth2',
+            'social_core.backends.github.GithubOAuth2',
+        ],
+        MISAGO_SOCIAL_AUTH_PROVIDERS_NAMES={
+            'facebook': "Facebook Connect",
+        }
+    )
+    def test_get_enabled_social_auth_sites_list_override_name(self):
+        self.assertEqual(get_enabled_social_auth_sites_list(), [
+            {
+                'id': 'facebook',
+                'name': 'Facebook Connect',
+            },
+            {
+                'id': 'github',
+                'name': 'GitHub',
+            }
+        ])