Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit already connected accounts when listing social providers #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions allauth_ui/templates/socialaccount/snippets/provider_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
{% get_providers as socialaccount_providers %}

{% for provider in socialaccount_providers %}
{% if provider.id == "openid" %}
{% for brand in provider.get_brands %}
<a class="flex items-center self-stretch justify-center h-12 mt-3 text-white uppercase rounded bg-stone-900 hover:bg-black"
href="{% provider_login_url provider.id openid=brand.openid_url process=process %}">{{brand.name}}</a>
{% endfor %}
{% endif %}
{% provider_connected provider user as is_connected %}
{% if not is_connected %}
{% if provider.id == "openid" %}
{% for brand in provider.get_brands %}
<a class="flex items-center self-stretch justify-center h-12 mt-3 text-white uppercase rounded bg-stone-900 hover:bg-black"
href="{% provider_login_url provider.id openid=brand.openid_url process=process %}">{{brand.name}}</a>
{% endfor %}
{% endif %}
<a class="flex items-center justify-center h-12 mt-3 text-white uppercase self-stretch rounded {{ provider | socialprovider_color }}"
href="{% provider_login_url provider.id process=process scope=scope auth_params=auth_params %}">{{provider.name}}</a>

{% endif %}
{% endfor %}
11 changes: 11 additions & 0 deletions allauth_ui/templatetags/allauth_ui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
from pathlib import Path
from allauth.socialaccount.models import SocialAccount

from django import template

Expand Down Expand Up @@ -29,3 +30,13 @@ def socialprovider_color(socialprovider):
if name in social_colors:
return f"social-{name}"
return "bg-stone-900 hover:bg-black"


@register.simple_tag
def provider_connected(socialprovider, user):
if not user.is_authenticated:
return False
# pylint: disable=no-member
return bool(
SocialAccount.objects.filter(provider=socialprovider.name.lower(), user=user)
)