diff --git a/wadium/requirements.txt b/wadium/requirements.txt index 7743816..bc77d94 100644 Binary files a/wadium/requirements.txt and b/wadium/requirements.txt differ diff --git a/wadium/wadium/adapters.py b/wadium/wadium/adapters.py index 653b489..0a68f8e 100644 --- a/wadium/wadium/adapters.py +++ b/wadium/wadium/adapters.py @@ -5,7 +5,7 @@ from rest_framework.serializers import ValidationError from allauth.exceptions import ImmediateHttpResponse from django.http import HttpResponseBadRequest - +from user.serializers import * class WadiumAccountAdapter(DefaultAccountAdapter): def is_open_for_signup(self, request): @@ -28,15 +28,24 @@ def save_user(self, request, sociallogin, form=None): return user except EmailAddress.DoesNotExist: pass - userprofile = { - 'email': email, - 'name': sociallogin.account.extra_data['name'], - 'profile_image': sociallogin.account.extra_data['picture'] - } + + if sociallogin.account.provider == 'google': + userprofile = { + 'email': email, + 'name': sociallogin.account.extra_data['name'], + 'profile_image': sociallogin.account.extra_data['picture'] + } + + elif sociallogin.account.provider == "facebook": + userprofile = { + 'email': email, + 'name': sociallogin.account.extra_data['name'], + 'profile_image': sociallogin.account.extra_data['picture']['data']['url'] + } + try: user = UserProfile.create_user( - UserProfile.get_unique_username(sociallogin.account.extra_data['email']), - userprofile) + UserProfile.get_unique_username(sociallogin.account.extra_data['email']), userprofile) except ValidationError as e: res = HttpResponseBadRequest(str(e.detail)) raise ImmediateHttpResponse(res) diff --git a/wadium/wadium/settings.py b/wadium/wadium/settings.py index b61f40a..1253014 100644 --- a/wadium/wadium/settings.py +++ b/wadium/wadium/settings.py @@ -46,6 +46,7 @@ 'user.apps.UserConfig', 'story.apps.StoryConfig', 'django.contrib.sites', + # 'sslserver', # apply https on localhost (temp) # allauth 'allauth', @@ -55,7 +56,8 @@ # provider 'user.providers.google', # 'allauth.socialaccount.providers.google', - # 'allauth.socialaccount.providers.facebook', + 'allauth.socialaccount.providers.facebook', + # 'user.providers.facebook', ] @@ -154,6 +156,26 @@ MAILJET_API_KEY = os.getenv('MAILJET_API_KEY') MAILJET_API_SECRET = os.getenv('MAILJET_API_SECRET') +SOCIALACCOUNT_PROVIDERS = { + 'facebook': { + 'METHOD': 'oauth2', + 'SCOPE': ['email', 'public_profile'], + 'AUTH_PARAMS': {'auth_type': 'reauthenticate'}, + 'FIELDS': [ + 'id', + 'email', + 'name', + 'verified', + 'picture', + 'locale', + 'updated_time'], + 'EXCHANGE_TOKEN': True, + 'LOCALE_FUNC': lambda request: 'kr_KR', + 'VERIFIED_EMAIL': False, + 'VERSION': 'v2.8' + } +} + AUTHENTICATION_BACKENDS = ( # Needed to login by username in Django admin, regardless of `allauth` 'django.contrib.auth.backends.ModelBackend', @@ -162,19 +184,6 @@ 'allauth.account.auth_backends.AuthenticationBackend', ) -SOCIALACCOUNT_PROVIDERS = { - 'google': { - # For each OAuth based provider, either add a ``SocialApp`` - # (``socialaccount`` app) containing the required client - # credentials, or list them here: - 'APP': { - 'client_id': '547861684988-3stvt30tjr8uu0j4llqeh8qpblf0a8uv.apps.googleusercontent.com', - 'secret': 'd-dpDCtOtOlBcrOozo81TJwB', - 'key': '' - } - } -} - ACCOUNT_AUTHENTICATED_LOGIN_REDIRECTS = False SOCIALACCOUNT_QUERY_EMAIL = True