depot/web/quotes/discordguild/adapter.py

27 lines
958 B
Python
Raw Permalink Normal View History

from django.conf import settings
from allauth.account.adapter import DefaultAccountAdapter
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
class BFOBAdapter(DefaultAccountAdapter):
def is_open_for_signup(self, request):
return False
class BFOBSocialAdapter(DefaultSocialAccountAdapter):
2021-01-20 22:20:07 +00:00
def is_open_for_signup(self, request, sociallogin):
return True
def pre_social_login(self, request, sociallogin):
guild_data = sociallogin.account.extra_data.get("guild_data", {})
roles = set(guild_data.get("roles", []))
should_be_admin = str(settings.DISCORD_ADMIN_ROLE) in roles or (
settings.DEBUG and guild_data == {}
)
user = sociallogin.user
if user.is_staff != should_be_admin or user.is_superuser != should_be_admin:
user.is_staff = should_be_admin
user.is_superuser = should_be_admin
user.save()
return