From 8bed5a8832344c2eec55b5f77a199030326274f3 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Thu, 21 Sep 2023 12:44:22 +0100 Subject: [PATCH] fix: add more reusable settings --- codeforlife/settings/django.py | 41 +++++++++++++++++-- codeforlife/user/__init__.py | 1 + codeforlife/user/authentication/__init__.py | 0 .../backends}/__init__.py | 0 .../backends}/email_and_password.py | 0 .../backends}/user_id_and_login_id.py | 0 .../username_and_password_and_class_id.py | 0 .../password_validators/__init__.py | 0 .../password_validators/common.py | 3 ++ .../password_validators/dependent_student.py | 3 ++ .../independent_student.py | 3 ++ .../password_validators/teacher.py | 3 ++ 12 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 codeforlife/user/authentication/__init__.py rename codeforlife/user/{auth_backends => authentication/backends}/__init__.py (100%) rename codeforlife/user/{auth_backends => authentication/backends}/email_and_password.py (100%) rename codeforlife/user/{auth_backends => authentication/backends}/user_id_and_login_id.py (100%) rename codeforlife/user/{auth_backends => authentication/backends}/username_and_password_and_class_id.py (100%) create mode 100644 codeforlife/user/authentication/password_validators/__init__.py create mode 100644 codeforlife/user/authentication/password_validators/common.py create mode 100644 codeforlife/user/authentication/password_validators/dependent_student.py create mode 100644 codeforlife/user/authentication/password_validators/independent_student.py create mode 100644 codeforlife/user/authentication/password_validators/teacher.py diff --git a/codeforlife/settings/django.py b/codeforlife/settings/django.py index 5ee4d201..bc352d9c 100644 --- a/codeforlife/settings/django.py +++ b/codeforlife/settings/django.py @@ -24,9 +24,9 @@ # https://docs.djangoproject.com/en/3.2/ref/settings/#authentication-backends AUTHENTICATION_BACKENDS = [ - "codeforlife.user.auth_backends.EmailAndPasswordBackend", - "codeforlife.user.auth_backends.UserIdAndLoginIdBackend", - "codeforlife.user.auth_backends.UsernameAndPasswordAndClassIdBackend", + "codeforlife.user.auth.backends.EmailAndPasswordBackend", + "codeforlife.user.auth.backends.UserIdAndLoginIdBackend", + "codeforlife.user.auth.backends.UsernameAndPasswordAndClassIdBackend", ] # Sessions @@ -52,7 +52,7 @@ # Default primary key field type # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field -DEFAULT_AUTO_FIELD = "django.db.models.AutoField" # TODO: use BugAutoField +DEFAULT_AUTO_FIELD = "django.db.models.AutoField" # TODO: use BigAutoField # CSRF # https://docs.djangoproject.com/en/3.2/ref/csrf/ @@ -84,3 +84,36 @@ "handlers": ["console"], }, } + +# URLs +# https://docs.djangoproject.com/en/4.2/ref/settings/#root-urlconf + +ROOT_URLCONF = "service.urls" + +# App +# https://docs.djangoproject.com/en/4.2/ref/settings/#wsgi-application + +WSGI_APPLICATION = "service.wsgi.application" + +# Password validation +# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators + +# TODO: replace with custom validators: +# 1. codeforlife.user.auth.password_validators.TeacherPasswordValidator +# 2. codeforlife.user.auth.password_validators.DependentStudentPasswordValidator +# 3. codeforlife.user.auth.password_validators.IndependentStudentPasswordValidator +# 4. codeforlife.user.auth.password_validators.CommonPasswordValidator +AUTH_PASSWORD_VALIDATORS = [ + { + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + }, +] diff --git a/codeforlife/user/__init__.py b/codeforlife/user/__init__.py index e69de29b..4795fd8e 100644 --- a/codeforlife/user/__init__.py +++ b/codeforlife/user/__init__.py @@ -0,0 +1 @@ +from . import authentication as auth diff --git a/codeforlife/user/authentication/__init__.py b/codeforlife/user/authentication/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/codeforlife/user/auth_backends/__init__.py b/codeforlife/user/authentication/backends/__init__.py similarity index 100% rename from codeforlife/user/auth_backends/__init__.py rename to codeforlife/user/authentication/backends/__init__.py diff --git a/codeforlife/user/auth_backends/email_and_password.py b/codeforlife/user/authentication/backends/email_and_password.py similarity index 100% rename from codeforlife/user/auth_backends/email_and_password.py rename to codeforlife/user/authentication/backends/email_and_password.py diff --git a/codeforlife/user/auth_backends/user_id_and_login_id.py b/codeforlife/user/authentication/backends/user_id_and_login_id.py similarity index 100% rename from codeforlife/user/auth_backends/user_id_and_login_id.py rename to codeforlife/user/authentication/backends/user_id_and_login_id.py diff --git a/codeforlife/user/auth_backends/username_and_password_and_class_id.py b/codeforlife/user/authentication/backends/username_and_password_and_class_id.py similarity index 100% rename from codeforlife/user/auth_backends/username_and_password_and_class_id.py rename to codeforlife/user/authentication/backends/username_and_password_and_class_id.py diff --git a/codeforlife/user/authentication/password_validators/__init__.py b/codeforlife/user/authentication/password_validators/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/codeforlife/user/authentication/password_validators/common.py b/codeforlife/user/authentication/password_validators/common.py new file mode 100644 index 00000000..b1be4f92 --- /dev/null +++ b/codeforlife/user/authentication/password_validators/common.py @@ -0,0 +1,3 @@ +# TODO: https://docs.djangoproject.com/en/3.2/topics/auth/passwords/#writing-your-own-validator +class CommonPasswordValidator: + pass diff --git a/codeforlife/user/authentication/password_validators/dependent_student.py b/codeforlife/user/authentication/password_validators/dependent_student.py new file mode 100644 index 00000000..0d499b4f --- /dev/null +++ b/codeforlife/user/authentication/password_validators/dependent_student.py @@ -0,0 +1,3 @@ +# TODO: https://docs.djangoproject.com/en/3.2/topics/auth/passwords/#writing-your-own-validator +class DependentStudentPasswordValidator: + pass diff --git a/codeforlife/user/authentication/password_validators/independent_student.py b/codeforlife/user/authentication/password_validators/independent_student.py new file mode 100644 index 00000000..9ef3f13d --- /dev/null +++ b/codeforlife/user/authentication/password_validators/independent_student.py @@ -0,0 +1,3 @@ +# TODO: https://docs.djangoproject.com/en/3.2/topics/auth/passwords/#writing-your-own-validator +class IndependentStudentPasswordValidator: + pass diff --git a/codeforlife/user/authentication/password_validators/teacher.py b/codeforlife/user/authentication/password_validators/teacher.py new file mode 100644 index 00000000..6625415d --- /dev/null +++ b/codeforlife/user/authentication/password_validators/teacher.py @@ -0,0 +1,3 @@ +# TODO: https://docs.djangoproject.com/en/3.2/topics/auth/passwords/#writing-your-own-validator +class TeacherPasswordValidator: + pass