django allauth社交认证检索到的电子邮件是否与现有用户的电子邮件相匹配?

时间:2014-07-17 17:27:24

标签: python django facebook email

这是我在Stack交换中的第一篇文章,我是Python和Django Noob试图开发一个应用程序。该应用程序使用django-registration进行用户注册,然后我开始插入' social'认证。我选择了allauth,因为它有能力在其他事情中执行身份验证。

我遇到了这个帖子中提出的同样问题:django allauth facebook redirects to signup when retrieved email matches an existing user's email?

如果数据库中已存在具有相同电子邮件地址的用户(由于使用本地注册路径注册),则

用户登录/注册失败。我尝试了上面提到的解决方案并遇到了问题。寻求帮助并在此提出建议。

我在socialadapter.py中的代码与以下路径

完全相同

的myproject / allauth / socialaccount / socialadapter.py

我的设置中有以下内容

LOGIN_URL = '/'
#LOGIN_REDIRECT_URL = '/'
LOGIN_REDIRECT_URL = "/users/{id}/mytags"
SOCIALACCOUNT_QUERY_EMAIL = True


ACCOUNT_AUTHENTICATION_METHOD='username_email'
SOCIALACCOUNT_EMAIL_REQUIRED = False

#create and use specific adapter to handle the issue reported here
# https://github.com/pennersr/django-allauth/issues/418

ACCOUNT_ADAPTER = "myproject.allauth.socialaccount.MyLoginAccountAdapter"
SOCIALACCOUNT_ADAPTER = 'myproject.allauth.socialaccount.MySocialAccountAdapter'

在启动runserver并访问facebook / login时,我看到以下问题

[17/Jul/2014 11:49:43] "GET /myproject/accounts2/facebook/login/ HTTP/1.1" 500 59
---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 58805) Traceback (most recent call last):   File "C:\Python27\Lib\SocketServer.py", line 593, in process_request_thread
    self.finish_request(request, client_address)   File "C:\Python27\Lib\SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)   File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 139, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)   File "C:\Python27\Lib\SocketServer.py", line 651, in __init__
    self.finish()   File "C:\Python27\Lib\SocketServer.py", line 710, in finish
    self.wfile.close()   File "C:\Python27\Lib\socket.py", line 279, in close
    self.flush()   File "C:\Python27\Lib\socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size]) error: [Errno 10053] An established connection was aborted by the software in your host machine
---------------------------------------- ERROR:django.request:Internal Server Error: /myproject/accounts2/facebook/login/callback/ Traceback (most recent call last):   File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 109, in get_response
    response = callback(request, *callback_args, **callback_kwargs)   File "myproject\allauth\socialaccount\providers\oauth2\views.py", line 51, in view
    return self.dispatch(request, *args, **kwargs)   File "myproject\allauth\socialaccount\providers\oauth2\views.py", line 98, in dispatch
    response=access_token)   File "myproject\allauth\socialaccount\providers\facebook\views.py", line 43, in complete_login
    return fb_complete_login(request, app, access_token)   File "myproject\allauth\socialaccount\providers\facebook\views.py", line 31, in fb_complete_login
    .sociallogin_from_response(request, extra_data)   File "myproject\allauth\socialaccount\providers\base.py", line 44, in sociallogin_from_response
    adapter = get_adapter()   File "myproject\allauth\socialaccount\adapter.py", line 150, in get_adapter
    return import_attribute(app_settings.ADAPTER)()   File "myproject\allauth\utils.py", line 97, in import_attribute
    ret = getattr(importlib.import_module(pkg), attr) AttributeError: 'module' object has no attribute 'MySocialAccountAdapter' [17/Jul/2014 11:49:46] "GET /myproject/accounts2/facebook/login/callback/?code=AQBShGWTHnGVvlo-fOVW7xjF9RUJo-k7P23zISHC70p aAR5uWYpnI46gpHFUCC5Rz-SviDyTITVRAUkZ-DhkZaHyBT2n5UBhhSwkACgCKTTgPrFLAZFBQs05AEZ67xfk-wRlF47DSjT26bbDdUmc1ptfFxP3W4qS5Y6b5Yrj iLTI3RMScOEM0EKUQjNySyj4XSAVk6wj4HcAbCVxiVv5QaH63ayxyt5Y5jQ0AOH3zsCngPaqFNJArXseMS6wfqSc8yDwcwWZKo1nGhcNtA9Gy_bqZNiTZSjPJguhT lBwbmDAJ9SUNI8AS3yzC-AKDtD2_bo&state=441rn77wUuLH HTTP/1.1" 500 147978

最初socialadapter.py甚至不会编译,所有其他人甚至在删除.pyc后都编译 我提到了这个帖子:pycompile for python3.2

并强制编译,但我仍然看到问题

非常感谢任何有关我可能在这里做错的建议。

谢谢你宝贵的时间。

-km

编辑:

环境

  • Python 2.7.5

  • allauth:0.17

1 个答案:

答案 0 :(得分:0)

好的,我发现了问题,我的适配器的设置条目缺少该类的完整路径。现在我可以使用Facebook登录。

但是我有另一个问题,我正在尝试在登录时为同一个应用启用Linked并在设置中包含以下条目

    SOCIALACCOUNT_PROVIDERS = \
{'linkedin':{'SCOPE': [ 'r_emailaddress',
                'r_fullprofile',
                'r_emailaddress',
                'r_contactinfo',
                'r_network'],
      'PROFILE_FIELDS':
            [
                'id',
                'first-name',
                'last-name',
                'email-address',
                'picture-url',
                'public-profile-url',
                'skills',
                'headline',
                'industry',
                'num-connections',
                'positions',
                'interests',
                'languages',
                'certifications',
                'educations',
                'courses',
                'three-current-positions',
                'three-past-positions',
                'recommendations-received',
                'honors-awards'
            ]
    },
 'facebook': {'SCOPE': ['email', 'user_about_me', 'user_birthday',
                            'user_education_history','user_work_history',
                            'user_hometown',
                            'user_location',
                            'user_religion_politics','user_subscriptions',
                            'read_stream',
                            'read_insights',
                            'read_friendlists',
                            'user_likes',
                            'user_interests',
                            'user_groups'
                            ],
                  'AUTH_PARAMS': {},
                  'METHOD': 'oauth2'
                },
}

现在当我使用登录页面时,我收到以下错误

[17/Jul/2014 22:26:28] "GET /myproject/accounts2/linkedin/login/?process=connect HTTP/1.1" 302 0
ERROR:django.request:Internal Server Error: /myproject/accounts2/linkedin/login/callback/
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 109, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "myproject\allauth\socialaccount\providers\oauth\views.py", line 35, in view
    return self.dispatch(request, *args, **kwargs)
  File "myproject\allauth\socialaccount\providers\oauth\views.py", line 90, in dispatch
    return complete_social_login(request, login)
  File "myproject\allauth\socialaccount\helpers.py", line 113, in complete_social_login
    sociallogin=sociallogin)
  File "C:\Python27\lib\site-packages\django\dispatch\dispatcher.py", line 172, in send
    response = receiver(signal=self, sender=sender, **named)
  File "myproject\allauth\socialaccount\socialadapter.py", line 50, in link_to_local_user
    email_address = sociallogin.account.extra_data['email']
KeyError: 'email'
[17/Jul/2014 22:26:50] "GET /myproject/accounts2/linkedin/login/callback/?oauth_token=77--d223fb8b-168f-4260-b93c-1a6e5ff2
e1e1&oauth_verifier=52724 HTTP/1.1" 500 139897

我不知道如何解决这个问题,因为LinkedIn的SCOPE有:' email-address',我如何解决这个问题,因为LinkedIn文档中的电子邮件字段也说电子邮件地址

LinkedIn fields

任何建议都表示赞赏。

对不起,我不知道如何在这个问题上给予赏金,而且我也没有足够的资金来处理这个问题。

TIA

-km