Ich habe festgestellt, dass die SAAD einen vorhandenen Benutzer nicht mit dem angemeldeten Benutzer verknüpfen kann. Dadurch werden mehrere Benutzer mit derselben E-Mail-Adresse erstellt. Ich habe versucht, dies in settings.py durch Auskommen außer Kraft zu setzen,AttributError: 'dict' Objekt hat kein Attribut 'Benutzer' beim Überschreiben von "social-app-auth-django" create_user
# 'social_core.pipeline.user.create_user',
ich dann eine Ansicht aus einem Benutzerprofil zu erstellen. Ich habe diese die Pipeline,
SOCIAL_AUTH_PIPELINE = (
...
'accounts.views.save_profile',
...
)
In accounts.views
,
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
Das Problem hier ist, dass ich Anforderung muß im Benutzer anmelden. Die Anmeldung erfordert Anfrage und authentifizierte Benutzer als Parameter. Angenommen, ich füge eine Anfrage als Parameter hinzu, bekomme ich eine 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)
Wie kann ich den Benutzer anmelden, Benutzername und Passwort bekannt?
Traceback des Fehlers:
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'