Я успешно зашифровал электронную почту пользователя с помощью пользовательской модели с https://github.com/incuna/django-pgcrypto-fields. Однако по какой-то причине allauth не шифрует тот же адрес электронной почты в таблице account_emailaddress. Эта таблица используется для определения, подтвердил ли пользователь свою электронную почту и является ли его электронная почта основной. Как я смогу зашифровать электронную почту в этой таблице? Имеет ли это какое-либо отношение к ACCOUNT_USER_MODEL_USERNAME_FIELD или ACCOUNT_USER_MODEL_EMAIL_FIELD?
Код:
Settings.py:
PGCRYPTO_KEY = 'hello'
INSTALLED_APPS = [
'pgcrypto',
]
Custom User Model models.py:
from pgcrypto import fields
class CustomUserManager(BaseUserManager):
def _create_user(self, email, password,is_staff, is_superuser, **extra_fields):
now = timezone.now()
if not email:
raise ValueError('The given email must be set')
email = self.normalize_email(email)
user = self.model(email=email,is_staff=is_staff, is_active=True,is_superuser=is_superuser, last_login=now,**extra_fields)
user.set_password(password)
user.save(using=self._db)
return user
def create_user(self, email, password=None, **extra_fields):
return self._create_user(email, password, False, False,**extra_fields)
def create_superuser(self, email, password, **extra_fields):
return self._create_user(email, password, True, True,**extra_fields)
class CustomUser(AbstractBaseUser, PermissionsMixin):
objects = CustomUserManager()
email = fields.EmailPGPSymmetricKeyField()
identifier = models.CharField(unique=True, max_length=50, default=uuid.uuid1)
username = models.CharField(_('username'), max_length=30, blank=True, default='', unique=True)
USERNAME_FIELD = 'username'
first_name = models.CharField(_('first name'), max_length=30, blank=True)
last_name = models.CharField(_('last name'), max_length=30, blank=True)
is_staff = models.BooleanField(_('staff status'), default=False,
help_text=_('Designates whether the user can log into this admin '
'site.'))
is_mod = models.BooleanField(_('moderator status'), default=False,
help_text=_('Designates whether the user can access mod pages and do mod things.'))
is_active = models.BooleanField(_('active'), default=True,
help_text=_('Designates whether this user should be treated as '
'active. Unselect this instead of deleting accounts.'))
EMAIL_FIELD = 'email'
REQUIRED_FIELDS = ['email']
Sql Результаты:
id | password | last_login | is_superuser | email | identifier | username | first_name | last_name | is_staff | is_mod | is_active
----+--------------------------------------------------------------------------------+-------------------------------+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------+----------+------------+-----------+----------+--------+-----------
5 | pbkdf2_sha256$180000$6D1SHJdM1DCm$72vBud5ji4S4v3Md2I7Ty8pnq91TEjwBVMb+Nu4lrnI= | 2020-03-21 22:59:45.127628+00 | f | \xc30d0407030286e239c36fe48d126dd24401086aecb7805d0e52fc77c32bc341f566153ee9e291d11f8972a6fd63a44282b5a7df09fad63d0bbd1eb1374980a9e10e13d2987a1289e193a749f496aec0195e1eb5e3 | a6c7d862-6bc7-11ea-a370-fcaa1473e99f | test56 | | | f | f | t
6 | pbkdf2_sha256$180000$WambLS3EnC5D$V+sBNopzxdRG4alBDU3Vf9kNsFnbs5gL5Kpb8vLeDes= | 2020-03-21 23:00:51.245735+00 | t | \xc30d04070302b53e0d09ee68807e73d245014797a80f79f8099bc887a1596ad684d760d2d1a18f7c6261ab3942202241d9c20a4d0c17bd5c165084e92e49d37c75f8f4ae1c4fbca80c09e344d06c56b2f9c9dc61b0a6 | c397b386-6bc7-11ea-a370-fcaa1473e99f | admin | | | t | f | t
(2 rows)
database_name=# select * from account_emailaddress;
id | email | verified | primary | user_id
----+----------------------+----------+---------+---------
3 | jambages@nkmvgg.xyz | f | t | 5
4 | brinellings@69xk4.us | t | t | 6
(2 rows)
Код Аллаута:
https://github.com/pennersr/django-allauth/blob/master/allauth/account/models.py#L18 -L72