From bdd97f4eeb6c1ada2443d5b7c9992caf9eac0621 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 5 Dec 2021 18:59:19 +0100 Subject: [PATCH] Begin setup of new auth system --- README.md | 46 +++++++++++++++++++ requirements.txt | 6 +-- ungleichuser/templates/base.html | 3 ++ .../templates/registration/login.html | 38 +++++++++++++++ ungleichuser/ungleichuser/settings.py | 3 +- ungleichuser/ungleichuser/urls.py | 4 +- ungleichuser/ungleichuser/v6v4.py | 5 ++ 7 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 ungleichuser/templates/base.html create mode 100644 ungleichuser/templates/registration/login.html create mode 100644 ungleichuser/ungleichuser/v6v4.py diff --git a/README.md b/README.md index 8ecdef7..ef38cf7 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,49 @@ pip install -r requirements.txt * Configure the `dal` django app (uses the [decouple](https://pypi.org/project/python-decouple/) library underneath) - Copy `dal/env.sample` to `dal/.env` - Populate `dal/.env` + +## Functionality + +- Allow user to register in a specific subtree +- Verify that user does not exist in another subtree +- Assign an id +- Allow password reset via Mail +- DB usage: for password reset? + +## Parameters + +LDAPSERVER + +## Steps / Views + +### Register view + +Form: [get] + +* captcha? +* username +* password1 +* password2 + +Post receiver: [post] + +* Validation / check if human +* E-Mail verification + +E-Mail verify: [get] + +* Create user + +### Password reset view + +* captcha +* username + + +## Tech notes + +### django-auth-ldap + +Depends on python-ldap, which fails on Alpine at the moment: + +* https://django-auth-ldap.readthedocs.io/en/latest/ diff --git a/requirements.txt b/requirements.txt index e6545bb..057191c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ -django==3.2.9 +django==4.0rc1 django-auth-ldap -python-ldap + +# To check django-bootstrap3 django-filter==2.1.0 python-decouple ldap3 djangorestframework -pyotp requests diff --git a/ungleichuser/templates/base.html b/ungleichuser/templates/base.html new file mode 100644 index 0000000..3a85819 --- /dev/null +++ b/ungleichuser/templates/base.html @@ -0,0 +1,3 @@ +{% block content %} +Your content here +{% endblock %} diff --git a/ungleichuser/templates/registration/login.html b/ungleichuser/templates/registration/login.html new file mode 100644 index 0000000..dce5873 --- /dev/null +++ b/ungleichuser/templates/registration/login.html @@ -0,0 +1,38 @@ +{% extends "base.html" %} + +{% block content %} + +{% if form.errors %} +

Your username and password didn't match. Please try again.

+{% endif %} + +{% if next %} + {% if user.is_authenticated %} +

Your account doesn't have access to this page. To proceed, + please login with an account that has access.

+ {% else %} +

Please login to see this page.

+ {% endif %} +{% endif %} + +
+{% csrf_token %} + + + + + + + + + +
{{ form.username.label_tag }}{{ form.username }}
{{ form.password.label_tag }}{{ form.password }}
+ + + +
+ +{# Assumes you setup the password_reset view in your URLconf #} +

Lost password?

+ +{% endblock %} diff --git a/ungleichuser/ungleichuser/settings.py b/ungleichuser/ungleichuser/settings.py index a327351..400fe79 100644 --- a/ungleichuser/ungleichuser/settings.py +++ b/ungleichuser/ungleichuser/settings.py @@ -10,6 +10,7 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/dev/ref/settings/ """ +import os from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. @@ -54,7 +55,7 @@ ROOT_URLCONF = 'ungleichuser.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], + 'DIRS': [os.path.join(BASE_DIR, 'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ diff --git a/ungleichuser/ungleichuser/urls.py b/ungleichuser/ungleichuser/urls.py index e9aef02..8d0fefe 100644 --- a/ungleichuser/ungleichuser/urls.py +++ b/ungleichuser/ungleichuser/urls.py @@ -14,8 +14,10 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +import django.contrib.auth +from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), + path('accounts/', include('django.contrib.auth.urls')), ] diff --git a/ungleichuser/ungleichuser/v6v4.py b/ungleichuser/ungleichuser/v6v4.py new file mode 100644 index 0000000..75fb54a --- /dev/null +++ b/ungleichuser/ungleichuser/v6v4.py @@ -0,0 +1,5 @@ +import ipaddress +import random + +v4_addr = ipaddress.IPv4Address(random.randint(0, 2**32)) +v6_addr = ipaddress.IPv6Address(random.randint(0, 2**128)