Browse Source

perf: support user email login

pull/13719/head
ibuler 4 months ago committed by 老广
parent
commit
6677985e4a
  1. 12
      apps/users/models/user/__init__.py

12
apps/users/models/user/__init__.py

@ -4,7 +4,7 @@
import uuid import uuid
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import AbstractUser from django.contrib.auth.models import AbstractUser, UserManager as _UserManager
from django.db import models from django.db import models
from django.shortcuts import reverse from django.shortcuts import reverse
from django.utils import timezone from django.utils import timezone
@ -32,6 +32,15 @@ __all__ = [
] ]
class UserManager(_UserManager):
def get_by_natural_key(self, username_or_mail):
q = models.Q(username=username_or_mail) | models.Q(email=username_or_mail)
user = self.filter(q).first()
if not user:
raise self.model.DoesNotExist
return user
class User( class User(
AuthMixin, AuthMixin,
SourceMixin, SourceMixin,
@ -127,6 +136,7 @@ class User(
null=True, blank=True, verbose_name=_("Date api key used") null=True, blank=True, verbose_name=_("Date api key used")
) )
date_updated = models.DateTimeField(auto_now=True, verbose_name=_("Date updated")) date_updated = models.DateTimeField(auto_now=True, verbose_name=_("Date updated"))
objects = UserManager()
DATE_EXPIRED_WARNING_DAYS = 5 DATE_EXPIRED_WARNING_DAYS = 5
def __str__(self): def __str__(self):

Loading…
Cancel
Save