-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Override allauth adapters to fix missing email issue
- Loading branch information
1 parent
dc454f4
commit 56b8ee1
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters