【发布时间】:2021-11-20 06:10:53
【问题描述】:
我的 django-react 应用程序几乎完成了所有模型、序列化程序和 API。但是现在我需要将身份验证方法更改为也使用电子邮件。
class User(AbstractUser):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
email = models.EmailField(unique=True)
# Notice there is no username field, because it is included in AbstractUser
我查看了一些可能的解决方案,但它们涉及使用 AbstractBaseUser,而其他一些则编写了一个完全省略 用户名 的自定义身份验证后端。这可能会破坏其他视图和前端,因为我们主要使用用户名。
我仍然想保留 用户名 并同时使用 用户名 和 电子邮件 进行身份验证。
有没有什么简单的想法(最好继续使用AbstractUser)我不必进行重大更改?
【问题讨论】:
标签: django authentication django-rest-framework