patch social-connections into settings

This commit is contained in:
Matthias 2021-09-01 01:09:23 +02:00
parent 3eeb6e161d
commit f997e67ea2
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
3 changed files with 23 additions and 5 deletions

View File

@ -37,7 +37,7 @@ from rest_framework.documentation import include_docs_urls
from .views import auth_request
from .views import IndexView, SearchView, DatabaseStatsView
from .views import SettingsView, EditUserView, SetPasswordView, CustomEmailView
from .views import SettingsView, EditUserView, SetPasswordView, CustomEmailView, CustomConnectionsView
from .views import CurrencyRefreshView
from .views import AppearanceSelectView, SettingCategorySelectView
from .views import DynamicJsView
@ -164,6 +164,7 @@ urlpatterns = [
# Single Sign On / allauth
# overrides of urlpatterns
url(r'^accounts/email/', CustomEmailView.as_view(), name='account_email'),
url(r'^accounts/social/connections/', CustomConnectionsView.as_view(), name='socialaccount_connections'),
url(r'^accounts/', include('allauth.urls')), # included urlpatterns
]

View File

@ -25,8 +25,10 @@ from django.views.generic.base import RedirectView, TemplateView
from djmoney.contrib.exchange.models import ExchangeBackend, Rate
from allauth.account.forms import AddEmailForm
from allauth.socialaccount.forms import DisconnectForm
from allauth.account.models import EmailAddress
from allauth.account.views import EmailView
from allauth.socialaccount.views import ConnectionsView
from common.settings import currency_code_default, currency_codes
@ -818,6 +820,10 @@ class SettingsView(TemplateView):
ctx['add_email_form'] = AddEmailForm
ctx["can_add_email"] = EmailAddress.objects.can_add_email(self.request.user)
# Form and context for allauth social-accounts
ctx["request"] = self.request
ctx['social_form'] = DisconnectForm(request=self.request)
return ctx
@ -832,6 +838,17 @@ class CustomEmailView(LoginRequiredMixin, EmailView):
return HttpResponseRedirect(self.success_url)
class CustomConnectionsView(LoginRequiredMixin, ConnectionsView):
"""
Override of allauths ConnectionsView to always show the settings but leave the functions allow
"""
success_url = reverse_lazy("settings")
def get(self, request, *args, **kwargs):
# always redirect to settings
return HttpResponseRedirect(self.success_url)
class CurrencyRefreshView(RedirectView):
"""
POST endpoint to refresh / update exchange rates

View File

@ -102,7 +102,7 @@
</div>
<div>
{% if form.accounts %}
{% if social_form.accounts %}
<p>{% blocktrans %}You can sign in to your account using any of the following third party accounts:{% endblocktrans %}</p>
@ -110,11 +110,11 @@
{% csrf_token %}
<fieldset>
{% if form.non_field_errors %}
<div id="errorMsg">{{ form.non_field_errors }}</div>
{% if social_form.non_field_errors %}
<div id="errorMsg">{{ social_form.non_field_errors }}</div>
{% endif %}
{% for base_account in form.accounts %}
{% for base_account in social_form.accounts %}
{% with base_account.get_provider_account as account %}
<div>
<label for="id_account_{{ base_account.id }}">