|
|
|
@ -5,7 +5,7 @@ from phonenumber_field.modelfields import PhoneNumberField |
|
|
|
from django.db import models |
|
|
|
from django.db import models |
|
|
|
from django.db.models.signals import post_save |
|
|
|
from django.db.models.signals import post_save |
|
|
|
from django.dispatch import receiver |
|
|
|
from django.dispatch import receiver |
|
|
|
from django.contrib.auth.models import AbstractUser |
|
|
|
from django.contrib.auth.models import AbstractUser, UserManager as BaseUserManager |
|
|
|
from django.contrib.postgres import fields as pgfields |
|
|
|
from django.contrib.postgres import fields as pgfields |
|
|
|
from django.utils.timezone import now |
|
|
|
from django.utils.timezone import now |
|
|
|
from django.utils.translation import gettext_lazy as _ |
|
|
|
from django.utils.translation import gettext_lazy as _ |
|
|
|
@ -16,6 +16,23 @@ from apps.notification.utils import send_email |
|
|
|
from apps.user.tasks import user_to_mixpanel |
|
|
|
from apps.user.tasks import user_to_mixpanel |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserManager(BaseUserManager): |
|
|
|
|
|
|
|
use_in_migrations = True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _create_user(self, username, email, password, **extra_fields): |
|
|
|
|
|
|
|
if not username: |
|
|
|
|
|
|
|
raise ValueError('The given username must be set') |
|
|
|
|
|
|
|
if not password: |
|
|
|
|
|
|
|
password = self.make_random_password() |
|
|
|
|
|
|
|
super().save(*args, **kwargs) |
|
|
|
|
|
|
|
email = self.normalize_email(email) |
|
|
|
|
|
|
|
username = self.model.normalize_username(username) |
|
|
|
|
|
|
|
user = self.model(username=username, email=email, **extra_fields) |
|
|
|
|
|
|
|
user.set_password(password) |
|
|
|
|
|
|
|
user.save(using=self._db) |
|
|
|
|
|
|
|
return user |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class User(AbstractUser): |
|
|
|
class User(AbstractUser): |
|
|
|
USER_ROLE = 0 |
|
|
|
USER_ROLE = 0 |
|
|
|
AUTHOR_ROLE = 1 |
|
|
|
AUTHOR_ROLE = 1 |
|
|
|
@ -65,11 +82,6 @@ class User(AbstractUser): |
|
|
|
class Meta(AbstractUser.Meta): |
|
|
|
class Meta(AbstractUser.Meta): |
|
|
|
ordering = ('-date_joined',) |
|
|
|
ordering = ('-date_joined',) |
|
|
|
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs): |
|
|
|
|
|
|
|
if self.password is None and self._password is None: |
|
|
|
|
|
|
|
self._password = self.objects.make_random_password() |
|
|
|
|
|
|
|
super().save(*args, **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def serialized(self): |
|
|
|
def serialized(self): |
|
|
|
user_data = serializers.user.UserSerializer(instance=self).data |
|
|
|
user_data = serializers.user.UserSerializer(instance=self).data |
|
|
|
user_data = dumps(user_data, ensure_ascii=False) |
|
|
|
user_data = dumps(user_data, ensure_ascii=False) |
|
|
|
|