diff options
Diffstat (limited to 'pyblackbird_cc/users/adapters.py')
-rw-r--r-- | pyblackbird_cc/users/adapters.py | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/pyblackbird_cc/users/adapters.py b/pyblackbird_cc/users/adapters.py deleted file mode 100644 index b13f3ca..0000000 --- a/pyblackbird_cc/users/adapters.py +++ /dev/null @@ -1,48 +0,0 @@ -from __future__ import annotations - -import typing - -from allauth.account.adapter import DefaultAccountAdapter -from allauth.socialaccount.adapter import DefaultSocialAccountAdapter -from django.conf import settings - -if typing.TYPE_CHECKING: - from allauth.socialaccount.models import SocialLogin - from django.http import HttpRequest - - from pyblackbird_cc.users.models import User - - -class AccountAdapter(DefaultAccountAdapter): - def is_open_for_signup(self, request: HttpRequest) -> bool: - return getattr(settings, "ACCOUNT_ALLOW_REGISTRATION", True) - - -class SocialAccountAdapter(DefaultSocialAccountAdapter): - def is_open_for_signup( - self, - request: HttpRequest, - sociallogin: SocialLogin, - ) -> bool: - return getattr(settings, "ACCOUNT_ALLOW_REGISTRATION", True) - - def populate_user( - self, - request: HttpRequest, - sociallogin: SocialLogin, - data: dict[str, typing.Any], - ) -> User: - """ - Populates user information from social provider info. - - See: https://docs.allauth.org/en/latest/socialaccount/advanced.html#creating-and-populating-user-instances - """ - user = super().populate_user(request, sociallogin, data) - if not user.name: - if name := data.get("name"): - user.name = name - elif first_name := data.get("first_name"): - user.name = first_name - if last_name := data.get("last_name"): - user.name += f" {last_name}" - return user |