adapters.py 839 B

12345678910111213141516171819202122
  1. from allauth.account.adapter import DefaultAccountAdapter
  2. from allauth.account.internal.flows.login import record_authentication
  3. from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
  4. from apps.users.utils import is_user_registration_open
  5. class CustomSocialAccountAdapter(DefaultSocialAccountAdapter):
  6. def is_open_for_signup(self, request, sociallogin):
  7. return is_user_registration_open()
  8. class CustomDefaultAccountAdapter(DefaultAccountAdapter):
  9. def is_open_for_signup(self, request):
  10. return is_user_registration_open()
  11. def save_user(self, request, user, form, commit=True):
  12. # Consider a signup a form of authentication
  13. user = super().save_user(request, user, form, commit)
  14. if commit:
  15. record_authentication(request, method="signup")
  16. return user