User model
This commit is contained in:
parent
bdfa5cab2a
commit
23a4a491b9
7 changed files with 113 additions and 10 deletions
21
datastore/managers.py
Normal file
21
datastore/managers.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
from django.contrib.auth.base_user import BaseUserManager
|
||||
|
||||
class UserManager(BaseUserManager):
|
||||
def create_user(self, email, **extra_fields):
|
||||
if not email:
|
||||
raise ValueError('The Email must be set')
|
||||
email = self.normalize_email(email)
|
||||
user = self.model(email=email, **extra_fields)
|
||||
user.save()
|
||||
return user
|
||||
|
||||
def create_superuser(self, email, **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('Superuser must have 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, **extra_fields)
|
34
datastore/migrations/0001_initial.py
Normal file
34
datastore/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
# Generated by Django 4.1 on 2022-08-08 12:59
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('auth', '0012_alter_user_first_name_max_length'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='User',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('password', models.CharField(max_length=128, verbose_name='password')),
|
||||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
|
||||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
|
||||
('email', models.EmailField(max_length=254, unique=True, verbose_name='email address')),
|
||||
('is_staff', models.BooleanField(default=False)),
|
||||
('is_active', models.BooleanField(default=True)),
|
||||
('date_joined', models.DateTimeField(default=django.utils.timezone.now)),
|
||||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
|
||||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
|
@ -1,3 +0,0 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
1
datastore/models/__init__.py
Normal file
1
datastore/models/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
from .auth import User
|
20
datastore/models/auth.py
Normal file
20
datastore/models/auth.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
|
||||
from ..managers import UserManager
|
||||
|
||||
|
||||
class User(AbstractBaseUser, PermissionsMixin):
|
||||
email = models.EmailField('email address', unique=True)
|
||||
is_staff = models.BooleanField(default=False)
|
||||
is_active = models.BooleanField(default=True)
|
||||
date_joined = models.DateTimeField(default=timezone.now)
|
||||
|
||||
USERNAME_FIELD = 'email'
|
||||
REQUIRED_FIELDS = []
|
||||
|
||||
objects = UserManager()
|
||||
|
||||
def __str__(self):
|
||||
return self.email
|
|
@ -9,9 +9,9 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
|||
CONFIG_PATH = BASE_DIR / "settings.ini"
|
||||
|
||||
ASK = AutoSecretKey(CONFIG_PATH)
|
||||
MONSTERCONFIG = MonsterConfig(CONFIG_PATH)
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
DEBUG = ASK.config.getboolean("DUMUZID", "Debug", fallback=False)
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
@ -64,17 +64,32 @@ WSGI_APPLICATION = 'dumuzid.wsgi.application'
|
|||
# Database
|
||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
if "MySQL" in ASK.config:
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': CONFIG_FILE.config.get("MySQL", "Database"),
|
||||
'USER': CONFIG_FILE.config.get("MySQL", "Username"),
|
||||
'PASSWORD': CONFIG_FILE.config.get("MySQL", "Password"),
|
||||
'HOST': CONFIG_FILE.config.get("MySQL", "Host", fallback="localhost"),
|
||||
'PORT': CONFIG_FILE.config.getint("MySQL", "Port", fallback=3306)
|
||||
}
|
||||
}
|
||||
|
||||
else:
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_USER_MODEL = 'datastore.User'
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
|
|
15
settings.dist.ini
Normal file
15
settings.dist.ini
Normal file
|
@ -0,0 +1,15 @@
|
|||
[DUMUZID]
|
||||
Debug = 0
|
||||
|
||||
# [MySQL]
|
||||
# Database = academon
|
||||
# Username = academon
|
||||
# Password = secret123!
|
||||
# Host = localhost
|
||||
# Port = 3306
|
||||
|
||||
# [S3]
|
||||
# AccessKey = academon
|
||||
# SecretKey = !!!verysecret!!!
|
||||
# Bucket = academon
|
||||
# Endpoint = https://minio.acade.mon
|
Loading…
Reference in a new issue