Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Allow linking the user's account to a social provider

Roland Geider63e8f9c86b67
diff --git a/settings/settings_global.py b/settings/settings_global.py
index e605eab4d..acb1fce61 100644
--- a/settings/settings_global.py
+++ b/settings/settings_global.py
@@ -273,6 +273,7 @@ MFA_PASSKEY_SIGNUP_ENABLED = False
#
ACCOUNT_LOGOUT_ON_GET = True
SOCIALACCOUNT_LOGIN_ON_GET = True
+SOCIALACCOUNT_QUERY_EMAIL = True
#
# allauth.headless — REST API used by the Flutter app for the full auth flow
diff --git a/wger/core/templates/user/preferences.html b/wger/core/templates/user/preferences.html
index 525d96e11..c94275c3e 100644
--- a/wger/core/templates/user/preferences.html
+++ b/wger/core/templates/user/preferences.html
@@ -1,5 +1,5 @@
{% extends "base.html" %}
-{% load i18n static wger_extras crispy_forms_tags %}
+{% load i18n static wger_extras crispy_forms_tags socialaccount %}
{% block title %}{% translate "Preferences" %}{% endblock %}
@@ -63,6 +63,13 @@
<span class="{% fa_class 'shield-halved' %}"></span>
{% translate "Two-factor authentication" %}
</a>
+ {% get_providers as socialaccount_providers %}
+ {% if socialaccount_providers %}
+ <a href="{% url 'socialaccount_connections' %}" class="dropdown-item">
+ <span class="{% fa_class 'link' %}"></span>
+ {% translate "Connected accounts" %}
+ </a>
+ {% endif %}
<a href="{% url 'core:user:api-key' %}" class="dropdown-item">
<span class="{% fa_class 'globe' %}"></span>
{% translate "API key" %}
diff --git a/wger/core/tests/test_auth_social.py b/wger/core/tests/test_auth_social.py
index de699f552..2100b9e2d 100644
--- a/wger/core/tests/test_auth_social.py
+++ b/wger/core/tests/test_auth_social.py
@@ -74,6 +74,29 @@ class SocialAuthEnabledLoginPageTestCase(WgerTestCase):
self.assertNotContains(response, 'or login with')
+@override_settings(WGER_SOCIAL_PROVIDERS=['wger'])
+class SocialAuthConnectionsLinkTestCase(WgerTestCase):
+ """The preferences page links to the connected-accounts page when social auth is enabled."""
+
+ @mock.patch(
+ 'allauth.socialaccount.adapter.DefaultSocialAccountAdapter.list_providers',
+ return_value=[_StubProvider()],
+ )
+ def test_link_shown_when_providers_configured(self, _):
+ self.user_login('test')
+ response = self.client.get(reverse('core:user:preferences'))
+ self.assertContains(response, reverse('socialaccount_connections'))
+
+ @mock.patch(
+ 'allauth.socialaccount.adapter.DefaultSocialAccountAdapter.list_providers',
+ return_value=[],
+ )
+ def test_link_hidden_without_providers(self, _):
+ self.user_login('test')
+ response = self.client.get(reverse('core:user:preferences'))
+ self.assertNotContains(response, reverse('socialaccount_connections'))
+
+
class WgerLoginViewContextTestCase(TestCase):
"""Unit tests for ``WgerLoginView.get_context_data``."""