From bb4cde4f2844f1c2a67885c9661e48ed37e43b78 Mon Sep 17 00:00:00 2001 From: liangliang Date: Sun, 26 Mar 2017 21:49:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Doauth=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E9=94=99=E8=AF=AFbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oauth/views.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/oauth/views.py b/oauth/views.py index cef4b15..ffc9346 100644 --- a/oauth/views.py +++ b/oauth/views.py @@ -45,8 +45,12 @@ def authorize(request): except ObjectDoesNotExist: pass if not author: - author = get_user_model(). \ - objects.create_user(username=user.nikename + '_' + str(user.openid), email=email) + result = get_user_model().objects.get_or_create(email=user.email) + author = result[0] + if result[1]: + author.username = user.nikename + '_' + str(user.openid) + author.save() + user.author = author user.save() login(request, author) @@ -71,13 +75,22 @@ def emailconfirm(request, id, sign): if not get_md5(settings.SECRET_KEY + str(id) + settings.SECRET_KEY).upper() == sign.upper(): return HttpResponseForbidden() oauthuser = get_object_or_404(OAuthUser, pk=id) - author = get_user_model().objects.get(pk=oauthuser.author_id) + author = None + if oauthuser.author: + author = get_user_model().objects.get(pk=oauthuser.author_id) + else: + result = get_user_model().objects.get_or_create(email=oauthuser.email) + author = result[0] + if result[1]: + author.username = oauthuser.nikename + '_' + str(oauthuser.openid) + author.save() + """ if oauthuser.email and author.email: login(request, author) return HttpResponseRedirect('/') - author.set_password('$%^Q1W2E3R4T5Y6,./') - author.email = oauthuser.email - author.save() + """ + oauthuser.author = author + oauthuser.save() login(request, author) site = Site.objects.get_current().domain