Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yuri-0415 committed Jan 5, 2021
1 parent 4cb0468 commit d127ff6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
Binary file modified wadium/requirements.txt
Binary file not shown.
25 changes: 17 additions & 8 deletions wadium/wadium/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down
37 changes: 23 additions & 14 deletions wadium/wadium/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
'user.apps.UserConfig',
'story.apps.StoryConfig',
'django.contrib.sites',
# 'sslserver', # apply https on localhost (temp)

# allauth
'allauth',
Expand All @@ -55,7 +56,8 @@
# provider
'user.providers.google',
# 'allauth.socialaccount.providers.google',
# 'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.facebook',
# 'user.providers.facebook',

]

Expand Down Expand Up @@ -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',
Expand All @@ -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

Expand Down

0 comments on commit d127ff6

Please sign in to comment.