Miroca_Server
This commit is contained in:
0
auth_miroca/__init__.py
Normal file
0
auth_miroca/__init__.py
Normal file
26
auth_miroca/admin.py
Normal file
26
auth_miroca/admin.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin
|
||||
from .forms import CustomUserCreationForm, CustomUserChangeForm
|
||||
from .models import CustomUser
|
||||
|
||||
class CustomUserAdmin(UserAdmin):
|
||||
add_form = CustomUserCreationForm
|
||||
form = CustomUserChangeForm
|
||||
model = CustomUser
|
||||
list_display = ('email', 'is_superuser','is_staff', 'is_active',)
|
||||
list_filter = ('email','is_superuser','is_staff', 'is_active',)
|
||||
fieldsets = (
|
||||
(None, {'fields': ('email', 'password')}),
|
||||
('Разрешения', {'fields': ('is_superuser','is_staff','is_active','groups',)}),
|
||||
('Пользователь',{'fields':('username','last_name','first_name','phone','org','address')}),
|
||||
('Регистрация и вход', {'fields': ('date_joined','last_login')}),
|
||||
)
|
||||
add_fieldsets = (
|
||||
(None, {
|
||||
'classes': ('wide',),
|
||||
'fields': ('email','is_superuser', 'password1', 'password2', 'is_staff', 'is_active')}
|
||||
),
|
||||
)
|
||||
search_fields = ('email',)
|
||||
ordering = ('email',)
|
||||
admin.site.register(CustomUser, CustomUserAdmin)
|
||||
6
auth_miroca/apps.py
Normal file
6
auth_miroca/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AuthMirocaConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'auth_miroca'
|
||||
10
auth_miroca/forms.py
Normal file
10
auth_miroca/forms.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
|
||||
from .models import CustomUser
|
||||
class CustomUserCreationForm(UserCreationForm):
|
||||
class Meta(UserCreationForm):
|
||||
model = CustomUser
|
||||
fields = ('email',)
|
||||
class CustomUserChangeForm(UserChangeForm):
|
||||
class Meta:
|
||||
model = CustomUser
|
||||
fields = ('email',)
|
||||
9
auth_miroca/logout.py
Normal file
9
auth_miroca/logout.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from django.shortcuts import render, redirect
|
||||
|
||||
def logout_view(func):
|
||||
def wrapper(request):
|
||||
if request.method == 'POST':
|
||||
request.session.clear()
|
||||
return redirect ('login')
|
||||
return func(request)
|
||||
return wrapper
|
||||
34
auth_miroca/managers.py
Normal file
34
auth_miroca/managers.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from django.contrib.auth.base_user import BaseUserManager
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class CustomUserManager(BaseUserManager):
|
||||
"""
|
||||
Custom user model manager where email is the unique identifiers
|
||||
for authentication instead of usernames.
|
||||
"""
|
||||
def create_user(self, email, password, **extra_fields):
|
||||
"""
|
||||
Create and save a user with the given email and password.
|
||||
"""
|
||||
if not email:
|
||||
raise ValueError(_("The Email must be set"))
|
||||
email = self.normalize_email(email)
|
||||
user = self.model(email=email, **extra_fields)
|
||||
user.set_password(password)
|
||||
user.save()
|
||||
return user
|
||||
|
||||
def create_superuser(self, email, password, **extra_fields):
|
||||
"""
|
||||
Create and save a SuperUser with the given email and password.
|
||||
"""
|
||||
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, password, **extra_fields)
|
||||
37
auth_miroca/migrations/0001_initial.py
Normal file
37
auth_miroca/migrations/0001_initial.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# Generated by Django 5.1.3 on 2024-11-29 06:19
|
||||
|
||||
import django.utils.timezone
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('auth', '0012_alter_user_first_name_max_length'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='CustomUser',
|
||||
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, verbose_name='Персонал')),
|
||||
('is_active', models.BooleanField(default=True, verbose_name='Активный')),
|
||||
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
|
||||
('username', models.CharField(max_length=255, null=True, verbose_name='username')),
|
||||
('image', models.ImageField(blank=True, null=True, upload_to='user/%Y/%m/%d', verbose_name='Изображение')),
|
||||
('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={
|
||||
'verbose_name': ('user',),
|
||||
'verbose_name_plural': 'Пользователь',
|
||||
},
|
||||
),
|
||||
]
|
||||
18
auth_miroca/migrations/0002_customuser_ipaddress.py
Normal file
18
auth_miroca/migrations/0002_customuser_ipaddress.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.1.3 on 2024-11-29 12:46
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auth_miroca', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='customuser',
|
||||
name='ipaddress',
|
||||
field=models.GenericIPAddressField(null=True),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,24 @@
|
||||
# Generated by Django 5.1.3 on 2024-11-29 12:53
|
||||
|
||||
import phone_field.models
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auth_miroca', '0002_customuser_ipaddress'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='customuser',
|
||||
name='last_name',
|
||||
field=models.CharField(max_length=255, null=True, verbose_name='Фамилия'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='customuser',
|
||||
name='phone',
|
||||
field=phone_field.models.PhoneField(blank=True, help_text='Контактный номер', max_length=31, null=True),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,26 @@
|
||||
# Generated by Django 5.1.3 on 2024-11-29 13:00
|
||||
|
||||
import address.models
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('address', '0003_auto_20200830_1851'),
|
||||
('auth_miroca', '0003_customuser_last_name_customuser_phone'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='customuser',
|
||||
name='address',
|
||||
field=address.models.AddressField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='address.address', verbose_name='Адрес'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='customuser',
|
||||
name='first_name',
|
||||
field=models.CharField(max_length=255, null=True, verbose_name='Имя'),
|
||||
),
|
||||
]
|
||||
21
auth_miroca/migrations/0005_alter_customuser_address.py
Normal file
21
auth_miroca/migrations/0005_alter_customuser_address.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# Generated by Django 5.1.3 on 2024-11-29 13:02
|
||||
|
||||
import address.models
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('address', '0003_auto_20200830_1851'),
|
||||
('auth_miroca', '0004_customuser_address_customuser_first_name'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='customuser',
|
||||
name='address',
|
||||
field=address.models.AddressField(null=True, on_delete=django.db.models.deletion.SET_NULL, to='address.address', verbose_name='Адрес'),
|
||||
),
|
||||
]
|
||||
17
auth_miroca/migrations/0006_remove_customuser_address.py
Normal file
17
auth_miroca/migrations/0006_remove_customuser_address.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# Generated by Django 5.1.3 on 2024-11-29 13:05
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auth_miroca', '0005_alter_customuser_address'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='customuser',
|
||||
name='address',
|
||||
),
|
||||
]
|
||||
18
auth_miroca/migrations/0007_customuser_ipaddress_mikrotik.py
Normal file
18
auth_miroca/migrations/0007_customuser_ipaddress_mikrotik.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.1.3 on 2024-11-29 16:51
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auth_miroca', '0006_remove_customuser_address'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='customuser',
|
||||
name='ipaddress_mikrotik',
|
||||
field=models.GenericIPAddressField(null=True),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,17 @@
|
||||
# Generated by Django 5.1.3 on 2024-11-29 17:28
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auth_miroca', '0007_customuser_ipaddress_mikrotik'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='customuser',
|
||||
name='ipaddress_mikrotik',
|
||||
),
|
||||
]
|
||||
0
auth_miroca/migrations/__init__.py
Normal file
0
auth_miroca/migrations/__init__.py
Normal file
33
auth_miroca/models.py
Normal file
33
auth_miroca/models.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from phone_field import PhoneField
|
||||
from address.models import AddressField
|
||||
|
||||
from .managers import CustomUserManager
|
||||
|
||||
|
||||
class CustomUser(AbstractBaseUser, PermissionsMixin):
|
||||
email = models.EmailField(_("email address"), unique=True)
|
||||
is_staff = models.BooleanField(default=False, verbose_name='Персонал')
|
||||
is_active = models.BooleanField(default=True, verbose_name='Активный')
|
||||
date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
|
||||
username = models.CharField(max_length=255, null=True, verbose_name='username')
|
||||
image = models.ImageField(upload_to='user/%Y/%m/%d', blank=True, null=True, verbose_name='Изображение')
|
||||
ipaddress=models.GenericIPAddressField(null=True)
|
||||
last_name=models.CharField(max_length=255, null=True,verbose_name='Фамилия')
|
||||
first_name=models.CharField(max_length=255,null=True,verbose_name='Имя')
|
||||
phone = PhoneField(blank=True,null=True, help_text='Контактный номер')
|
||||
|
||||
USERNAME_FIELD = 'email'
|
||||
REQUIRED_FIELDS = []
|
||||
|
||||
objects = CustomUserManager()
|
||||
|
||||
def __str__(self):
|
||||
return self.email
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'user',
|
||||
verbose_name_plural = 'Пользователь'
|
||||
3
auth_miroca/tests.py
Normal file
3
auth_miroca/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
3
auth_miroca/views.py
Normal file
3
auth_miroca/views.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
Reference in New Issue
Block a user