users started

This commit is contained in:
Tom Irgang 2023-04-23 12:55:10 +02:00
parent 9b8ecba15d
commit 017410fa6b
16 changed files with 137 additions and 3 deletions

View file

@ -41,6 +41,7 @@ ALLOWED_HOSTS = [
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'repapp_users.apps.RepappUsersConfig',
'repapp.apps.RepappConfig', 'repapp.apps.RepappConfig',
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
@ -150,3 +151,7 @@ EMAIL_PORT = (int)(os.getenv("DJANGO_EMAIL_PORT", '25'))
EMAIL_HOST_USER = os.getenv("DJANGO_EMAIL_HOST_USER", None) EMAIL_HOST_USER = os.getenv("DJANGO_EMAIL_HOST_USER", None)
EMAIL_HOST_PASSWORD = os.getenv("DJANGO_EMAIL_HOST_PASSWORD", None) EMAIL_HOST_PASSWORD = os.getenv("DJANGO_EMAIL_HOST_PASSWORD", None)
EMAIL_USE_TLS = os.getenv("DJANGO_EMAIL_USE_TLS", 'true') in ('true', '1', 't') EMAIL_USE_TLS = os.getenv("DJANGO_EMAIL_USE_TLS", 'true') in ('true', '1', 't')
AUTH_USER_MODEL = "repapp_users.CustomUser"
AUTHENTICATION_BACKENDS = [
"repapp_users.backends.EmailBackend", "django.contrib.auth.backends.ModelBackend"]

View file

@ -22,5 +22,7 @@ from django.conf.urls.static import static
urlpatterns = [ urlpatterns = [
path("", include("repapp.urls")), path("", include("repapp.urls")),
path("", include("repapp_users.urls")),
path('users/', include('django.contrib.auth.urls')),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View file

@ -2,7 +2,6 @@
Admin interface configuration for RepApp. Admin interface configuration for RepApp.
""" """
from django.contrib import admin from django.contrib import admin
from .models import (Organisator, Cafe, Question, Device, from .models import (Organisator, Cafe, Question, Device,
Reparateur, Appointment, Guest, Candidate) Reparateur, Appointment, Guest, Candidate)

View file

@ -18,7 +18,8 @@ class Migration(migrations.Migration):
migrations.AlterField( migrations.AlterField(
model_name='device', model_name='device',
name='device', name='device',
field=models.CharField(max_length=200, verbose_name='Art des Geräts'), field=models.CharField(
max_length=200, verbose_name='Art des Geräts'),
), ),
migrations.AlterField( migrations.AlterField(
model_name='device', model_name='device',
@ -28,6 +29,7 @@ class Migration(migrations.Migration):
migrations.AlterField( migrations.AlterField(
model_name='device', model_name='device',
name='manufacturer', name='manufacturer',
field=models.CharField(max_length=200, verbose_name='Hersteller & Modell/Typ'), field=models.CharField(
max_length=200, verbose_name='Hersteller & Modell/Typ'),
), ),
] ]

View file

View file

@ -0,0 +1,4 @@
from django.contrib import admin
from .models import CustomUser
admin.site.register(CustomUser)

View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class RepappUsersConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'repapp_users'

View file

@ -0,0 +1,15 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend
class EmailBackend(ModelBackend):
def authenticate(self, request, username=None, password=None, **kwargs):
UserModel = get_user_model()
try:
user = UserModel.objects.get(email=username)
except UserModel.DoesNotExist:
return None
else:
if user.check_password(password):
return user
return None

View file

View file

@ -0,0 +1,44 @@
# Generated by Django 4.2 on 2023-04-23 10:29
import django.contrib.auth.models
import django.contrib.auth.validators
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='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')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('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,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]

View file

@ -0,0 +1,14 @@
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils.translation import gettext_lazy as _
class CustomUser(AbstractUser):
email = models.EmailField(unique=True, verbose_name=_("eMail Adresse"))
class Meta:
verbose_name = _('Benutzer')
verbose_name_plural = _('Benutzer')
def __str__(self):
return f'{self.email}'

View file

@ -0,0 +1,33 @@
{% extends "repapp/base.html" %}
{% block content %}
{% if form.errors %}<p>Your username and password didn't match. Please try again.</p>{% endif %}
{% if next %}
{% if user.is_authenticated %}
<p>
Your account doesn't have access to this page. To proceed,
please login with an account that has access.
</p>
{% else %}
<p>Please login to see this page.</p>
{% endif %}
{% endif %}
<form method="post" action="{% url 'login' %}">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>
<input type="submit" value="login">
<input type="hidden" name="next" value="{{ next }}">
</form>
{# Assumes you setup the password_reset view in your URLconf #}
<p>
<a href="{% url 'password_reset' %}">Lost password?</a>
</p>
{% endblock %}

View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View file

@ -0,0 +1,4 @@
from django.urls import path, include
urlpatterns = [
]

View file

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.