Skip to content

Commit 36e38b9

Browse files
committed
修复oauth登录用户名可能重复bug
1 parent a332ce2 commit 36e38b9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

oauth/views.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@ def authorize(request):
9797
result = get_user_model().objects.get_or_create(email=user.email)
9898
author = result[0]
9999
if result[1]:
100-
author.username = user.nikename
100+
try:
101+
get_user_model().objects.get(username=user.nikename)
102+
except ObjectDoesNotExist:
103+
author.username = user.nikename
104+
else:
105+
author.username = "djangoblog" + datetime.datetime.now().strftime('%y%m%d%I%M%S')
101106
author.source = 'authorize'
102107
author.save()
103108

0 commit comments

Comments
 (0)