0

SAAD이 기존 사용자를 소셜 인증 로그인 사용자와 연결하지 못하는 것으로 나타났습니다. 이것은 동일한 전자 메일 주소를 가진 여러 사용자를 생성합니다. 나는 이것을 settings.py에서 주석 처리하여 무시하려고 시도했습니다.AttributeError : 'dict'객체에 'social-app-auth-django'를 재정의하는 동안 'user'속성이 없습니다. create_user

# 'social_core.pipeline.user.create_user', 

그런 다음 사용자 프로필을 생성하는보기를 만들었습니다. 여기 문제는 내가 사용자 로그인을 요청해야 할 것입니다이에게 파이프 라인, accounts.views에서

SOCIAL_AUTH_PIPELINE = (
... 
'accounts.views.save_profile', 
... 
) 

,

def save_profile(backend, user, response, *args, **kwargs): 
    username = "" 
    if backend.name == "google-oauth2": 
     email = response["emails"][0]["value"] 
     existing_user = User.objects.get(email=email) 
     username = existing_user.username 
     password = existing_user.password 
     authenticated_user = authenticate(username=username, password=password) 
     login(request,authenticated_user) # I need request to login the user 

을 추가했다. 로그인에는 요청 및 인증 된 사용자가 매개 변수로 필요합니다. 매개 변수로 요청을 추가한다고 가정하면 AttributeError: 'dict' object has no attribute 'user'이됩니다.

def save_profile(request, backend, user, response, *args, **kwargs): 
    username = "" 
    if backend.name == "google-oauth2": 
     email = response["emails"][0]["value"] 
     existing_user = User.objects.get(email=email) 
     username = existing_user.username 
     password = existing_user.password 
     authenticated_user = authenticate(username=username, password=password) 
     login(request,authenticated_user) 

사용자 이름과 암호를 알고있는 사용자를 어떻게 로그인합니까? 오류의

역 추적은 :

Traceback (most recent call last): 
    File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 149, in get_response 
response = self.process_exception_by_middleware(e, request) 
    File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 147, in get_response 
response = wrapped_callback(request, *callback_args, **callback_kwargs) 
    File "/Library/Python/2.7/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func 
response = view_func(request, *args, **kwargs) 
    File "/Library/Python/2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view 
return view_func(*args, **kwargs) 
    File "/Library/Python/2.7/site-packages/social_django/utils.py", line 50, in wrapper 
return func(request, backend, *args, **kwargs) 
    File "/Library/Python/2.7/site-packages/social_django/views.py", line 28, in complete 
redirect_name=REDIRECT_FIELD_NAME, *args, **kwargs) 
    File "/Library/Python/2.7/site-packages/social_core/actions.py", line 41, in do_complete 
user = backend.complete(user=user, *args, **kwargs) 
    File "/Library/Python/2.7/site-packages/social_core/backends/base.py", line 39, in complete 
return self.auth_complete(*args, **kwargs) 
    File "/Library/Python/2.7/site-packages/social_core/utils.py", line 253, in wrapper 
return func(*args, **kwargs) 
    File "/Library/Python/2.7/site-packages/social_core/backends/oauth.py", line 398, in auth_complete 
*args, **kwargs) 
    File "/Library/Python/2.7/site-packages/social_core/utils.py", line 253, in wrapper 
return func(*args, **kwargs) 
    File "/Library/Python/2.7/site-packages/social_core/backends/oauth.py", line 409, in do_auth 
return self.strategy.authenticate(*args, **kwargs) 
    File "/Library/Python/2.7/site-packages/social_django/strategy.py", line 115, in authenticate 
return authenticate(*args, **kwargs) 
    File "/Library/Python/2.7/site-packages/django/contrib/auth/__init__.py", line 74, in authenticate 
user = backend.authenticate(**credentials) 
    File "/Library/Python/2.7/site-packages/social_core/backends/base.py", line 79, in authenticate 
return self.pipeline(pipeline, *args, **kwargs) 
    File "/Library/Python/2.7/site-packages/social_core/backends/base.py", line 82, in pipeline 
out = self.run_pipeline(pipeline, pipeline_index, *args, **kwargs) 
    File "/Library/Python/2.7/site-packages/social_core/backends/base.py", line 107, in run_pipeline 
result = func(*args, **out) or {} 
    File "/Users/swaggerjeevan07/Desktop/django/mysite/accounts/views.py", line 76, in save_profile 
login(request,authenticated_user) 
    File "/Library/Python/2.7/site-packages/django/contrib/auth/__init__.py", line 97, in login 
user = request.user  # This is the issue 
AttributeError: 'dict' object has no attribute 'user' 

답변

0

내가 한 모든 create_user 위의 파이프 라인에 social_core.pipeline.social_auth.associate_by_email를 추가했다. 이제 획득 한 소셜 시큐어 전자 메일과 이미 연결된 계정이 있는지 확인합니다. 그렇지 않으면 새 사용자가 만들어집니다.

SOCIAL_AUTH_PIPELINE = (
    ... 
    'social_core.pipeline.social_auth.associate_by_email', 
    'social_core.pipeline.user.create_user', 
    'accounts.views.save_profile', 
    'social_core.pipeline.social_auth.associate_user', 
    ... 
) 

def save_profile 보이는 같은 :

def save_profile(backend, user, response, *args, **kwargs): 
    if backend.name == "google-oauth2": 
     # A dot in username will have url issues 
     username = user.username.replace(".","_") 
     user.username = username 
     user.first_name = user.first_name.capitalize() 
     user.last_name = user.last_name.capitalize() 
관련 문제