2021-01-20 00:22:54 +00:00
|
|
|
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):
|
2021-01-20 00:22:54 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
def pre_social_login(self, request, sociallogin):
|
|
|
|
guild_data = sociallogin.account.extra_data.get("guild_data", {})
|
|
|
|
roles = set(guild_data.get("roles", []))
|
2021-01-20 03:16:29 +00:00
|
|
|
should_be_admin = str(settings.DISCORD_ADMIN_ROLE) in roles or (
|
|
|
|
settings.DEBUG and guild_data == {}
|
|
|
|
)
|
2021-01-20 00:22:54 +00:00
|
|
|
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
|