Last active
December 2, 2019 08:29
-
-
Save LeeHanYeong/a6472f206a05f67999e58732e42d4e36 to your computer and use it in GitHub Desktop.
Social Login username
This file contains hidden or 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
# users/social/adapter.py | |
from allauth.account.utils import user_username, user_email, user_field | |
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter | |
from allauth.utils import valid_email_or_none | |
class SocialAdapter(DefaultSocialAccountAdapter): | |
def populate_user(self, request, sociallogin, data): | |
provider = sociallogin.account.provider | |
unique_id = sociallogin.account.extra_data['id'] | |
username = f'{provider}_{unique_id}' | |
first_name = data.get('first_name') | |
last_name = data.get('last_name') | |
email = data.get('email') | |
name = data.get('name') | |
user = sociallogin.user | |
user_username(user, username) | |
user_email(user, valid_email_or_none(email) or '') | |
name_parts = (name or '').partition(' ') | |
user_field(user, 'first_name', first_name or name_parts[0]) | |
user_field(user, 'last_name', last_name or name_parts[2]) | |
return user |
This file contains hidden or 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
# django-allauth | |
ACCOUNT_LOGOUT_ON_GET = False | |
ACCOUNT_UNIQUE_EMAIL = False | |
ACCOUNT_EMAIL_VERIFICATION = 'none' | |
ACCOUNT_EMAIL_REQUIRED = False | |
ACCOUNT_USERNAME_REQUIRED = True | |
SOCIALACCOUNT_ADAPTER = 'users.social.adapter.SocialAdapter' |
This file contains hidden or 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
path('facebook-login', FacebookLoginView.as_view(), name='facebook-login'), |
This file contains hidden or 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
from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter | |
from rest_auth.registration.views import SocialLoginView | |
class FacebookLoginView(SocialLoginView): | |
""" | |
Facebook Login | |
--- | |
페이스북 로그인, access_token만 전달하면 완료 | |
""" | |
adapter_class = FacebookOAuth2Adapter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment