Allow logged-in user to connect social accounts

- Add link to social account management from the profile page
- Override allauth templated related to managing social account connections
- Did my best to apply reasonable styles per other pages
This commit is contained in:
Lacey Williams Henschel
2023-08-03 09:52:34 -07:00
parent 414575b27c
commit ffb20e4c79
3 changed files with 80 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ from django.views.generic.edit import FormView
from django.views.generic.base import TemplateView
from allauth.account.forms import ChangePasswordForm
from allauth.socialaccount.models import SocialAccount
from rest_framework import generics
from rest_framework import viewsets
@@ -141,8 +142,22 @@ class NewCurrentUserProfileView(LoginRequiredMixin, SuccessMessageMixin, Templat
context["profile_preferences_form"] = PreferencesForm(
instance=self.request.user.preferences
)
context["social_accounts"] = self.get_social_accounts()
return context
def get_social_accounts(self):
account_data = []
for account in SocialAccount.objects.filter(user=self.request.user):
provider_account = account.get_provider_account()
account_data.append(
{
"id": account.pk,
"provider": account.provider,
"name": provider_account.to_str(),
}
)
return account_data
def post(self, request, *args, **kwargs):
"""
Process each form submission individually if present