-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
173 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
|
||
# | ||
staticfiles/ | ||
gitignore/ | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.contrib import admin | ||
from . import models | ||
|
||
|
||
@admin.register(models.User) | ||
class UserAdmin(admin.ModelAdmin): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class CustomAuthConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'custom_auth' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Generated by Django 4.2.13 on 2024-11-18 07:47 | ||
|
||
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='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')), | ||
('email', models.EmailField(max_length=50, unique=True)), | ||
('first_name', models.CharField(blank=True, max_length=25)), | ||
('last_name', models.CharField(blank=True, max_length=25)), | ||
('is_active', models.BooleanField(default=True)), | ||
('is_staff', models.BooleanField(default=False, verbose_name='is staff')), | ||
('is_superuser', models.BooleanField(default=False, verbose_name='is superuser')), | ||
('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, | ||
}, | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from django.db import models | ||
|
||
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager | ||
from django.contrib.auth.models import PermissionsMixin | ||
|
||
|
||
class UserManager(BaseUserManager): | ||
def create_user( | ||
self, | ||
email, | ||
first_name, | ||
last_name, | ||
password=None, | ||
is_active=True, | ||
is_staff=False, | ||
is_admin=False, | ||
): | ||
if not email: | ||
raise ValueError("User must have an email address") | ||
if not password: | ||
raise ValueError("User must have a password") | ||
|
||
user_obj = self.model( | ||
email=self.normalize_email(email), | ||
first_name=first_name, | ||
last_name=last_name, | ||
) | ||
user_obj.set_password(password) | ||
user_obj.is_staff = is_staff | ||
user_obj.is_superuser = is_admin | ||
user_obj.active = is_active | ||
user_obj.save(using=self.db) | ||
return user_obj | ||
|
||
def create_staffuser(self, email, first_name, last_name, password=None): | ||
user = self.create_user( | ||
email, first_name, last_name, password=password, is_staff=True | ||
) | ||
return user | ||
|
||
def create_superuser(self, email, first_name="", last_name="", password=None): | ||
user = self.create_user( | ||
email, | ||
first_name, | ||
last_name, | ||
password=password, | ||
is_staff=True, | ||
is_admin=True, | ||
) | ||
return user | ||
|
||
|
||
class User(AbstractBaseUser, PermissionsMixin): | ||
email = models.EmailField(max_length=50, unique=True) | ||
|
||
first_name = models.CharField(max_length=25, blank=True) | ||
last_name = models.CharField(max_length=25, blank=True) | ||
|
||
is_active = models.BooleanField(default=True) | ||
is_staff = models.BooleanField("is staff", default=False) | ||
is_superuser = models.BooleanField("is superuser", default=False) | ||
|
||
USERNAME_FIELD = "email" | ||
REQUIRED_FIELDS = [] | ||
|
||
objects = UserManager() | ||
|
||
def __str__(self): | ||
return self.email |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |