Merge branch 'master' into feat/ldap
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
from django import forms
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.forms import UsernameField
|
||||
from myauth.models import get_typed_user_model
|
||||
|
||||
User = get_user_model()
|
||||
User = get_typed_user_model()
|
||||
|
||||
|
||||
class AdminUserCreationForm(forms.ModelForm):
|
||||
|
||||
37
myauth/migrations/0003_auto_20201119_0810.py
Normal file
37
myauth/migrations/0003_auto_20201119_0810.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# Generated by Django 3.1.1 on 2020-11-19 08:10
|
||||
|
||||
from django.db import migrations, models
|
||||
import myauth.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("myauth", "0002_auto_20200515_0801"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelManagers(
|
||||
name="user",
|
||||
managers=[
|
||||
("objects", myauth.models.UserManager()),
|
||||
],
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="user",
|
||||
name="first_name",
|
||||
field=models.CharField(blank=True, max_length=150, verbose_name="first name"),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="user",
|
||||
name="username",
|
||||
field=models.CharField(
|
||||
error_messages={"unique": "A user with that username already exists."},
|
||||
help_text="Required. 150 characters or fewer. Letters, digits and ./-/_ only.",
|
||||
max_length=150,
|
||||
unique=True,
|
||||
validators=[myauth.models.UnicodeUsernameValidator()],
|
||||
verbose_name="username",
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -1,3 +1,5 @@
|
||||
import typing as t
|
||||
|
||||
from django.contrib.auth.models import AbstractUser, UserManager as DjangoUserManager
|
||||
from django.core import validators
|
||||
from django.db import models
|
||||
@@ -13,14 +15,15 @@ class UnicodeUsernameValidator(validators.RegexValidator):
|
||||
|
||||
|
||||
class UserManager(DjangoUserManager):
|
||||
def get_by_natural_key(self, username):
|
||||
def get_by_natural_key(self, username: str):
|
||||
return self.get(**{self.model.USERNAME_FIELD + "__iexact": username})
|
||||
|
||||
|
||||
class User(AbstractUser):
|
||||
id: int
|
||||
username_validator = UnicodeUsernameValidator()
|
||||
|
||||
objects = UserManager()
|
||||
objects: UserManager = UserManager()
|
||||
|
||||
username = models.CharField(
|
||||
_("username"),
|
||||
@@ -28,9 +31,21 @@ class User(AbstractUser):
|
||||
unique=True,
|
||||
help_text=_("Required. 150 characters or fewer. Letters, digits and ./-/_ only."),
|
||||
validators=[username_validator],
|
||||
error_messages={"unique": _("A user with that username already exists."),},
|
||||
error_messages={
|
||||
"unique": _("A user with that username already exists."),
|
||||
},
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def normalize_username(cls, username):
|
||||
def normalize_username(cls, username: str):
|
||||
return super().normalize_username(username).lower()
|
||||
|
||||
|
||||
UserType = User
|
||||
|
||||
|
||||
def get_typed_user_model() -> UserType:
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
ret: t.Any = get_user_model()
|
||||
return ret
|
||||
|
||||
Reference in New Issue
Block a user