24 lines
882 B
Python
24 lines
882 B
Python
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):
|
|
def is_open_for_signup(self, request):
|
|
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
|
|
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
|