From 3c405bff6d5f1569187eba6bc2c95eef8d365e9d Mon Sep 17 00:00:00 2001 From: clonbg Date: Thu, 16 Feb 2023 17:03:02 +0100 Subject: [PATCH] empezado models authentication --- README.md | 4 ++++ authentication/.null-ls_325153_models.py | 11 ++++++++++ authentication/models.py | 27 ++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 authentication/.null-ls_325153_models.py diff --git a/README.md b/README.md index 9f7cbf6..aeeee53 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,7 @@ Lista de la compra #### Commit 2 - 00:29:00 + +#### Commit 3 + +- 00:40:40 diff --git a/authentication/.null-ls_325153_models.py b/authentication/.null-ls_325153_models.py new file mode 100644 index 0000000..276ebed --- /dev/null +++ b/authentication/.null-ls_325153_models.py @@ -0,0 +1,11 @@ +from django.contrib.auth.models import AbstractUser +from django.contrib.auth.base_user import BaseUserManager + + +class CustomUserMnager(BaseUserManager): + + def create_user(self, email, password): + pass + + def create_superuser(self, email, password): + pass diff --git a/authentication/models.py b/authentication/models.py index 71a8362..3bf7a81 100644 --- a/authentication/models.py +++ b/authentication/models.py @@ -1,3 +1,26 @@ -from django.db import models +from django.contrib.auth.models import AbstractUser +from django.contrib.auth.base_user import BaseUserManager -# Create your models here. + +class CustomUserMnager(BaseUserManager): + + def create_user(self, email, password, **extra_fields): + if not email: + raise ValueError(_("El email es necesario")) + email = self.normalize_email(email) + new_user = self.model(email=email) + new_user.set_password(password) + new_user.save() + return new_user + + def create_superuser(self, email, password, **extra_fields): + extra_fields.setdefault('is_staff', True) + extra_fields.setdefault('is_superuser', True) + extra_fields.setdefault('is_active', True) + if extra_fields.get('is_staff') is not True: + raise ValueError(_('Debe pertenecer al staff')) + if extra_fields.get('is_superuser') is not True: + raise ValueError(_('Debe ser un superusuario')) + if extra_fields.get('is_active') is not True: + raise ValueError(_('Debe ser un usuario activo')) + return self.create_user(email, password, **extra_fields)