custom user model added
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -9,6 +9,9 @@
|
|||||||
# environment variables
|
# environment variables
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
# Migrations
|
||||||
|
**/migrations
|
||||||
|
|
||||||
# Node artifact files
|
# Node artifact files
|
||||||
node_modules/
|
node_modules/
|
||||||
dist/
|
dist/
|
||||||
|
|||||||
@@ -11,11 +11,13 @@ This README aims to document functionality of backend as well as required steps
|
|||||||
|
|
||||||
- Clone repository:
|
- Clone repository:
|
||||||
`git clone git@bitbucket.org:enreda/back-latienda.git`
|
`git clone git@bitbucket.org:enreda/back-latienda.git`
|
||||||
- From inside the project's folder:
|
- Create file `.env` from `example.env` and populate fields correctly
|
||||||
|
|
||||||
|
From inside the project's folder:
|
||||||
|
- Make migrations:
|
||||||
```
|
```
|
||||||
python manage.py makemigrations core companies products history stats
|
python manage.py makemigrations core companies products history stats
|
||||||
python migrate
|
python migrate
|
||||||
|
|
||||||
```
|
```
|
||||||
|
- Start server in development mode: `python manage.py runserver`
|
||||||
|
|
||||||
|
|||||||
@@ -100,6 +100,8 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
AUTH_USER_MODEL = 'core.CustomUser'
|
||||||
|
|
||||||
|
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/2.2/topics/i18n/
|
# https://docs.djangoproject.com/en/2.2/topics/i18n/
|
||||||
|
|||||||
@@ -1,3 +1,61 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
|
||||||
|
from django.contrib.auth.models import PermissionsMixin
|
||||||
|
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
class UserManager(BaseUserManager):
|
||||||
|
use_in_migrations = True
|
||||||
|
|
||||||
|
def _create_user(self, email, password, **extra_fields):
|
||||||
|
"""
|
||||||
|
Creates and saves a User with the given email and password.
|
||||||
|
"""
|
||||||
|
if not email:
|
||||||
|
raise ValueError('The given email must be set')
|
||||||
|
email = self.normalize_email(email)
|
||||||
|
user = self.model(email=email, **extra_fields)
|
||||||
|
user.set_password(password)
|
||||||
|
user.save(using=self._db)
|
||||||
|
return user
|
||||||
|
|
||||||
|
def create_user(self, email, password=None, **extra_fields):
|
||||||
|
extra_fields.setdefault('is_superuser', False)
|
||||||
|
return self._create_user(email, password, **extra_fields)
|
||||||
|
|
||||||
|
def create_superuser(self, email, password, **extra_fields):
|
||||||
|
extra_fields.setdefault('is_superuser', True)
|
||||||
|
extra_fields.setdefault('is_staff', True)
|
||||||
|
|
||||||
|
if extra_fields.get('is_superuser') is not True:
|
||||||
|
raise ValueError('Superuser must have is_superuser=True.')
|
||||||
|
|
||||||
|
return self._create_user(email, password, **extra_fields)
|
||||||
|
|
||||||
|
|
||||||
|
class CustomUser(AbstractBaseUser, PermissionsMixin):
|
||||||
|
|
||||||
|
email = models.EmailField('Dirección de email', unique=True)
|
||||||
|
full_name = models.CharField('Nombre completo', max_length=100, blank=True)
|
||||||
|
role = models.CharField('Rol', max_length=100, blank=True, null=True)
|
||||||
|
notify = models.BooleanField('Notificar', default=False, null=True)
|
||||||
|
provider = models.CharField('Proveedor', max_length=1000, blank=True, null=True) # red social de registro
|
||||||
|
email_verified = models.BooleanField('Email verificado', default=False, null=True)
|
||||||
|
company = None # models.ForeignKey(Empresa, null=True, on_delete=models.DO_NOTHING)
|
||||||
|
|
||||||
|
is_active = models.BooleanField('Activo', default=True)
|
||||||
|
is_staff = models.BooleanField('Empleado',default=False )
|
||||||
|
|
||||||
|
modified = models.DateTimeField(auto_now=True, null=True, blank=True)
|
||||||
|
created = models.DateTimeField(auto_now_add=True, null=True, blank=True)
|
||||||
|
last_visit = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
|
objects = UserManager()
|
||||||
|
|
||||||
|
USERNAME_FIELD = 'email'
|
||||||
|
REQUIRED_FIELDS = []
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = 'Usuario'
|
||||||
|
verbose_name_plural = 'Usuarios'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user