From 39724044d07ba43a250ca1af2ff547137efd03cf Mon Sep 17 00:00:00 2001 From: lneoe Date: Wed, 14 Oct 2015 16:02:36 +0800 Subject: [PATCH] use `opened` as username --- docs/backends/qq.rst | 6 +++++- social/backends/qq.py | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/docs/backends/qq.rst b/docs/backends/qq.rst index 2f3a932d3..97b7486c3 100644 --- a/docs/backends/qq.rst +++ b/docs/backends/qq.rst @@ -22,6 +22,10 @@ QQ implemented OAuth2 protocol for their authentication mechanism. To enable The values for ``nickname``, ``figureurl_qq_1`` and ``gender`` will be stored in the ``extra_data`` field. The ``nickname`` will be used as the account -username. ``figureurl_qq_1`` can be used as the profile image. +username. ``figureurl_qq_1`` can be used as the profile image. sometimes +nickname will duplicate with another qq account, to avoid this issue it's +possible to use ``openid`` as ``username`` by define this setting:: + + SOCIAL_AUTH_QQ_USE_OPENID_AS_USERNAME = True .. _QQ: http://connect.qq.com/ diff --git a/social/backends/qq.py b/social/backends/qq.py index 0a50df77a..4894b6016 100644 --- a/social/backends/qq.py +++ b/social/backends/qq.py @@ -25,8 +25,26 @@ class QQOAuth2(BaseOAuth2): ] def get_user_details(self, response): + """ + Return user detail from QQ account + sometimes nickname will duplicate with another qq account, to avoid + this issue it's possible to use `openid` as `username` by define + `SOCIAL_AUTH_QQ_USE_OPENID_AS_USERNAME = True` + """ + if self.setting('SOCIAL_AUTH_QQ_USE_OPENID_AS_USERNAME', False): + username = response.get('openid', '') + else: + username = response.get('nickname', '') + + fullname, first_name, last_name = self.get_user_names( + first_name=response.get('nickname', '') + ) + return { - 'username': response.get('nickname', '') + 'username': username, + 'fullname': fullname, + 'first_name': first_name, + 'last_name': last_name } def get_openid(self, access_token):