django - Django 3rd 方登录重复电子邮件
问题描述
我设置了我的 django 应用程序,以便能够使用 google 和 facebook 3rd 方应用程序登录。但是,每当我已经有一个使用已经存在的 gmail 帐户注册的帐户时,我会得到一个奇怪的注册页面,如下所示:
Menu:
Sign In
Sign Up
Sign Up
You are about to use your Google account to login to example.com. As a final step, please complete the following form:
Username:
testuser
An account already exists with this e-mail address. Please sign in to that account first, then connect your Google account.
E-mail (optional):
email@test.com
Sign Up »
有没有办法解决这个问题,所以它可以要求用户提供不同的电子邮件,而不是像这样中断?当用户之前没有通过应用程序注册时,不会出现此问题。
解决方案
简单的。创建一个测试函数,检查用户(尝试登录时)是否已经存在,基于电子邮件、用户名或你有什么,并将该消息返回给用户。
例如:
def login(request):
if request.method == 'POST':
# perform some logic
try:
User.objects.filter(email=email).exists()
return "User with email already exists"
except User.objects.filter(email=email).DoesNotExist():
return "User doesn't exist yet"
推荐阅读
- regex - How to write PathPrefixStripRegex in Traefik?
- python - 在字符串中使用 (" ") 将字符串更改为浮点数
- python - pandas DataFrame中的按位不正确(包括NaN)
- r - Errors when making tables with the flextable package
- html - 如何本地化有序列表的十进制数?
- php - How to make composer use php72 instead of php
- spring-boot - org.springframework.data.repository.query.parser.Part有什么用?
- javascript - 递归函数中的异步每个系列
- python - 需要在 Airflow 中访问 DockerOperator 中的调度时间
- spring - How to filter @PathParam for xss protection?