Skip to content

Commit

Permalink
Override allauth adapters to fix missing email issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mvandenburgh committed Dec 9, 2024
1 parent dc454f4 commit 56b8ee1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
28 changes: 28 additions & 0 deletions dandiapi/allauth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from uuid import uuid4

from allauth.account.adapter import DefaultAccountAdapter
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter

if TYPE_CHECKING:
from allauth.socialaccount.models import SocialLogin
from django.contrib.auth.models import User


class DandiAccountAdapter(DefaultAccountAdapter):
_USERNAME_SUFFIX = '-dandi'

def populate_username(self, request, user: User):
# Call the super class in case of potential side effects
super().populate_username(request, user)
user.username = str(uuid4()) + self._USERNAME_SUFFIX


class DandiSocialAccountAdapter(DefaultSocialAccountAdapter):
def save_user(self, request, sociallogin: SocialLogin, form=None):
user: User = super().save_user(request, sociallogin, form)
user.username = user.email
user.save()
return user
3 changes: 3 additions & 0 deletions dandiapi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def mutate_configuration(configuration: type[ComposedConfiguration]):
# Disable github oauth by default
ENABLE_GITHUB_OAUTH = False

ACCOUNT_ADAPTER = 'dandiapi.allauth.DandiAccountAdapter'
SOCIALACCOUNT_ADAPTER = 'dandiapi.allauth.DandiSocialAccountAdapter'


class DevelopmentConfiguration(DandiMixin, DevelopmentBaseConfiguration):
# This makes pydantic model schema allow URLs with localhost in them.
Expand Down

0 comments on commit 56b8ee1

Please sign in to comment.