-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from forza-mor-rotterdam/custom-user-model
custom user model
- Loading branch information
Showing
16 changed files
with
245 additions
and
111 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from apps.authenticatie.models import Gebruiker | ||
from django.contrib import admin | ||
from django.contrib.auth.admin import UserAdmin | ||
|
||
|
||
class GebruikerAdmin(UserAdmin): | ||
model = Gebruiker | ||
list_display = ( | ||
"email", | ||
"is_staff", | ||
"is_active", | ||
) | ||
list_filter = ( | ||
"email", | ||
"is_staff", | ||
"is_active", | ||
) | ||
fieldsets = ( | ||
(None, {"fields": ("email", "password")}), | ||
("Permissions", {"fields": ("is_staff", "is_active")}), | ||
) | ||
add_fieldsets = ( | ||
( | ||
None, | ||
{ | ||
"classes": ("wide",), | ||
"fields": ("email", "password1", "password2", "is_staff", "is_active"), | ||
}, | ||
), | ||
) | ||
search_fields = ("email",) | ||
ordering = ("email",) | ||
|
||
|
||
admin.site.register(Gebruiker, GebruikerAdmin) |
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 AuthenticatieConfig(AppConfig): | ||
name = "apps.authenticatie" | ||
verbose_name = "Authenticatie" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from django.contrib.auth.base_user import BaseUserManager | ||
from django.contrib.auth.hashers import make_password | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
|
||
class GebruikerManager(BaseUserManager): | ||
""" | ||
Gebruiker 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 username, 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.password = make_password(password) | ||
user.save(using=self._db) | ||
return user | ||
|
||
def create_user(self, email, password=None, **extra_fields): | ||
""" | ||
Create and save a User with the given email and password. | ||
""" | ||
extra_fields.setdefault("is_staff", False) | ||
extra_fields.setdefault("is_superuser", False) | ||
return self._create_user(email, password, **extra_fields) | ||
|
||
def create_superuser(self, email, password=None, **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) |
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,107 @@ | ||
# Generated by Django 3.2.16 on 2023-06-29 08:17 | ||
|
||
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="Gebruiker", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
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", | ||
), | ||
), | ||
( | ||
"first_name", | ||
models.CharField( | ||
blank=True, max_length=150, verbose_name="first name" | ||
), | ||
), | ||
( | ||
"last_name", | ||
models.CharField( | ||
blank=True, max_length=150, verbose_name="last name" | ||
), | ||
), | ||
( | ||
"is_staff", | ||
models.BooleanField( | ||
default=False, | ||
help_text="Designates whether the user can log into this admin site.", | ||
verbose_name="staff status", | ||
), | ||
), | ||
( | ||
"is_active", | ||
models.BooleanField( | ||
default=True, | ||
help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.", | ||
verbose_name="active", | ||
), | ||
), | ||
( | ||
"date_joined", | ||
models.DateTimeField( | ||
default=django.utils.timezone.now, verbose_name="date joined" | ||
), | ||
), | ||
("email", models.EmailField(max_length=254, unique=True)), | ||
( | ||
"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": "users", | ||
"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,16 @@ | ||
from apps.authenticatie.managers import GebruikerManager | ||
from django.contrib.auth.models import AbstractUser | ||
from django.contrib.gis.db import models | ||
|
||
|
||
class Gebruiker(AbstractUser): | ||
username = None | ||
email = models.EmailField(unique=True) | ||
|
||
USERNAME_FIELD = "email" | ||
REQUIRED_FIELDS = [] | ||
|
||
objects = GebruikerManager() | ||
|
||
def __str__(self): | ||
return self.email |
25 changes: 0 additions & 25 deletions
25
app/apps/authenticatie/templates/auth/gebruiker_informatie.html
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
app/apps/authenticatie/templates/auth/login_verplicht.html
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.