Initial working version with minor bugs
This commit is contained in:
parent
f946e4933a
commit
71b3993326
83 changed files with 34485 additions and 173 deletions
19
django_project/middleware.py
Normal file
19
django_project/middleware.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
from django.conf import settings
|
||||
from django.contrib.auth import login
|
||||
from accounts.models import CustomUser
|
||||
from django.contrib.auth.models import User
|
||||
class AutoLoginMiddleware:
|
||||
"""
|
||||
In development, automatically logs in as a predefined user if the request is anonymous.
|
||||
"""
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
# Only perform auto-login if in DEBUG mode and user is not authenticated.
|
||||
if settings.DEBUG and not request.user.is_authenticated:
|
||||
user = CustomUser.objects.get(email='rob@badblocks.email')
|
||||
login(request, user, backend='django.contrib.auth.backends.ModelBackend')
|
||||
|
||||
response = self.get_response(request)
|
||||
return response
|
||||
|
|
@ -33,12 +33,20 @@ INSTALLED_APPS = [
|
|||
# Third-party
|
||||
"allauth",
|
||||
"allauth.account",
|
||||
'allauth.socialaccount.providers.google',
|
||||
"crispy_forms",
|
||||
"crispy_bootstrap5",
|
||||
"debug_toolbar",
|
||||
"el_pagination",
|
||||
"tailwind",
|
||||
#"theme",
|
||||
"django_browser_reload",
|
||||
# Local
|
||||
"accounts",
|
||||
"pages",
|
||||
"cards",
|
||||
"home",
|
||||
"trades.apps.TradesConfig",
|
||||
"friend_codes"
|
||||
]
|
||||
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#middleware
|
||||
|
|
@ -53,6 +61,8 @@ MIDDLEWARE = [
|
|||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
"allauth.account.middleware.AccountMiddleware", # django-allauth
|
||||
"django_browser_reload.middleware.BrowserReloadMiddleware",
|
||||
"django_project.middleware.AutoLoginMiddleware",
|
||||
]
|
||||
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf
|
||||
|
|
@ -79,24 +89,24 @@ TEMPLATES = [
|
|||
]
|
||||
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": BASE_DIR / "db.sqlite3",
|
||||
}
|
||||
}
|
||||
#DATABASES = {
|
||||
# "default": {
|
||||
# "ENGINE": "django.db.backends.sqlite3",
|
||||
# "NAME": BASE_DIR / "db.sqlite3",
|
||||
# }
|
||||
#}
|
||||
|
||||
# For Docker/PostgreSQL usage uncomment this and comment the DATABASES config above
|
||||
# DATABASES = {
|
||||
# "default": {
|
||||
# "ENGINE": "django.db.backends.postgresql",
|
||||
# "NAME": "postgres",
|
||||
# "USER": "postgres",
|
||||
# "PASSWORD": "postgres",
|
||||
# "HOST": "db", # set in docker-compose.yml
|
||||
# "PORT": 5432, # default postgres port
|
||||
# }
|
||||
# }
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.postgresql",
|
||||
"NAME": "postgres",
|
||||
"USER": "postgres",
|
||||
"PASSWORD": "postgres",
|
||||
"HOST": "db", # set in docker-compose.yml
|
||||
"PORT": 5432, # default postgres port
|
||||
}
|
||||
}
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#auth-password-validators
|
||||
|
|
@ -173,7 +183,9 @@ DEFAULT_FROM_EMAIL = "root@localhost"
|
|||
# django-debug-toolbar
|
||||
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#internal-ips
|
||||
INTERNAL_IPS = ["127.0.0.1"]
|
||||
import socket
|
||||
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
|
||||
INTERNAL_IPS = [ip[:-1] + "1" for ip in ips]
|
||||
|
||||
# https://docs.djangoproject.com/en/dev/topics/auth/customizing/#substituting-a-custom-user-model
|
||||
AUTH_USER_MODEL = "accounts.CustomUser"
|
||||
|
|
@ -199,4 +211,70 @@ ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE = False
|
|||
ACCOUNT_USERNAME_REQUIRED = False
|
||||
ACCOUNT_AUTHENTICATION_METHOD = "email"
|
||||
ACCOUNT_EMAIL_REQUIRED = True
|
||||
#ACCOUNT_EMAIL_VERIFICATION = "mandatory"
|
||||
ACCOUNT_EMAIL_VERIFICATION = "none"
|
||||
ACCOUNT_CHANGE_EMAIL = True
|
||||
ACCOUNT_UNIQUE_EMAIL = True
|
||||
ACCOUNT_SIGNUP_FORM_HONEYPOT_FIELD = "friend_code"
|
||||
SOCIALACCOUNT_EMAIL_AUTHENTICATION = True
|
||||
SOCIALACCOUNT_EMAIL_AUTHENTICATION_AUTO_CONNECT = True
|
||||
SOCIALACCOUNT_ONLY = False
|
||||
|
||||
# SOCIALACCOUNT_PROVIDERS = {
|
||||
# "google": {
|
||||
# # For each OAuth based provider, either add a ``SocialApp``
|
||||
# # (``socialaccount`` app) containing the required client
|
||||
# # credentials, or list them here:
|
||||
# "APPS": [
|
||||
# {
|
||||
# "client_id": "123",
|
||||
# "secret": "456",
|
||||
# "key": ""
|
||||
# },
|
||||
# ],
|
||||
# # These are provider-specific settings that can only be
|
||||
# # listed here:
|
||||
# "SCOPE": [
|
||||
# "profile",
|
||||
# "email",
|
||||
# ],
|
||||
# "AUTH_PARAMS": {
|
||||
# "access_type": "offline",
|
||||
# },
|
||||
# },
|
||||
# "openid_connect": {
|
||||
# # Optional PKCE defaults to False, but may be required by your provider
|
||||
# # Applies to all APPS.
|
||||
# "OAUTH_PKCE_ENABLED": True,
|
||||
# "APPS": [
|
||||
# {
|
||||
# "provider_id": "nintendo",
|
||||
# "name": "Nintendo Account",
|
||||
# "client_id": "your.service.id",
|
||||
# "secret": "your.service.secret",
|
||||
# "settings": {
|
||||
# "server_url": "https://my.server.example.com",
|
||||
# # Optional token endpoint authentication method.
|
||||
# # May be one of "client_secret_basic", "client_secret_post"
|
||||
# # If omitted, a method from the the server's
|
||||
# # token auth methods list is used
|
||||
# "token_auth_method": "client_secret_basic",
|
||||
# },
|
||||
# },
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
|
||||
if DEBUG:
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": "django.core.cache.backends.dummy.DummyCache",
|
||||
}
|
||||
}
|
||||
else:
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
|
||||
"LOCATION": "unique-snowflake",
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,11 @@ from django.urls import path, include
|
|||
urlpatterns = [
|
||||
path("admin/", admin.site.urls),
|
||||
path("accounts/", include("allauth.urls")),
|
||||
path("", include("pages.urls")),
|
||||
path("", include("home.urls")),
|
||||
path("cards/", include("cards.urls")),
|
||||
path('friend_codes/', include('friend_codes.urls')),
|
||||
path("trades/", include("trades.urls")),
|
||||
path("__reload__/", include("django_browser_reload.urls")),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue