Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the bug #20

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Binary file added blango/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added blango/__pycache__/settings.cpython-36.pyc
Binary file not shown.
Binary file added blango/__pycache__/urls.cpython-36.pyc
Binary file not shown.
Binary file added blango/__pycache__/wsgi.cpython-36.pyc
Binary file not shown.
299 changes: 207 additions & 92 deletions blango/settings.py
Original file line number Diff line number Diff line change
@@ -1,125 +1,240 @@
"""
Django settings for blango project.
import os
from pathlib import Path
from configurations import Configuration
from configurations import values
import dj_database_url
import argon2


PASSWORD_HASHERS = [
"django.contrib.auth.hashers.Argon2PasswordHasher",
"django.contrib.auth.hashers.PBKDF2PasswordHasher",
"django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher",
"django.contrib.auth.hashers.BCryptSHA256PasswordHasher",

]
class Dev(Configuration):

Generated by 'django-admin startproject' using Django 3.2.7.
"""
Django settings for blango project.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
Generated by 'django-admin startproject' using Django 3.2.7.

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/

from pathlib import Path
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
AUTH_USER_MODEL = "blango_auth.User"

PASSWORD_HASHERS = [
"django.contrib.auth.hashers.Argon2PasswordHasher",
"django.contrib.auth.hashers.PBKDF2PasswordHasher",
"django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher",
"django.contrib.auth.hashers.BCryptSHA256PasswordHasher",

]

LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"filters": {
"require_debug_false": {
"()": "django.utils.log.RequireDebugFalse",
},
},
"formatters": {
"verbose": {
"format": "{levelname} {asctime} {module} {process:d} {thread:d} {message}",
"style": "{",
},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout",
"formatter": "verbose",
},
"mail_admins": {
"level": "ERROR",
"class": "django.utils.log.AdminEmailHandler",
"filters": ["require_debug_false"],
},
},
"loggers": {
"django.request": {
"handlers": ["mail_admins"],
"level": "ERROR",
"propagate": True,
},
},
"root": {
"handlers": ["console"],
"level": "DEBUG",
},
}

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-+sn%dpa!086+g+%44z9*^j^q-u4n!j(#wl)x9a%_1op@zz2+1-'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TIME_ZONE = values.Value("UTC")


# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-+sn%dpa!086+g+%44z9*^j^q-u4n!j(#wl)x9a%_1op@zz2+1-'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']
X_FRAME_OPTIONS = 'ALLOW-FROM ' + os.environ.get('CODIO_HOSTNAME') + '-8000.codio.io'
CSRF_COOKIE_SAMESITE = None
CSRF_TRUSTED_ORIGINS = ['https://' + os.environ.get('CODIO_HOSTNAME') + '-8000.codio.io']
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SAMESITE = 'None'
SESSION_COOKIE_SAMESITE = 'None'


# Application definition

INSTALLED_APPS = [
"blango_auth",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.sites",
"django.contrib.staticfiles",
"blog",
"crispy_forms",
"crispy_bootstrap5",
"debug_toolbar",
"allauth",
"allauth.account",
"allauth.socialaccount",
"allauth.socialaccount.providers.google"
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
#'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
#'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'blango.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

ALLOWED_HOSTS = []
WSGI_APPLICATION = 'blango.wsgi.application'


# Application definition
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

ROOT_URLCONF = 'blango.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
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',
},
]

WSGI_APPLICATION = 'blango.wsgi.application'

# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
LANGUAGE_CODE = 'en-us'

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


USE_I18N = True

# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

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',
},
]
USE_L10N = True

USE_TZ = True

# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

TIME_ZONE = 'UTC'
STATIC_URL = '/static/'

USE_I18N = True
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

USE_L10N = True
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

USE_TZ = True
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
CRISPY_TEMPLATE_PACK = "bootstrap5"
INTERNAL_IPS = ["192.168.10.226"]
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
ACCOUNT_ACTIVATION_DAYS = 7

SITE_ID = 1
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = "email"

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

class Prod(Dev):
BASE_DIR = Path(__file__).resolve().parent.parent
DEBUG = True
DEBUG = values.BooleanValue(True)
SECRET_KEY = values.SecretValue()
ALLOWED_HOSTS = values.ListValue(["localhost", "0.0.0.0", ".codio.io"])

STATIC_URL = '/static/'

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DATABASES = values.DatabaseURLValue(f"sqlite:///{BASE_DIR}/db.sqlite3")
DATABASES = {
"default": dj_database_url.config(default=f"sqlite:///{BASE_DIR}/db.sqlite3"),
"alternative": dj_database_url.config(
"ALTERNATIVE_DATABASE_URL",
default=f"sqlite:///{BASE_DIR}/alternative_db.sqlite3",
),
}

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
27 changes: 26 additions & 1 deletion blango/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,34 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
import debug_toolbar
from django.conf import settings
from django.contrib import admin
from django.urls import path
from django.urls import path, include
from django_registration.backends.activation.views import RegistrationView
from blango_auth.forms import BlangoRegistrationForm

import blog.views
import blango_auth.views



urlpatterns = [
path('admin/', admin.site.urls),
path("ip/", blog.views.get_ip),
path("", blog.views.index),
path("post/<slug>/", blog.views.post_detail, name="blog-post-detail"),
path("accounts/", include("django.contrib.auth.urls")),
path("accounts/profile/", blango_auth.views.profile, name="profile"),
path(
"accounts/register/",
RegistrationView.as_view(form_class=BlangoRegistrationForm),
name="django_registration_register",),
path("accounts/", include("django_registration.backends.activation.urls")),
path("accounts/", include("allauth.urls")),
]

if settings.DEBUG:
urlpatterns += [
path("__debug__/", include(debug_toolbar.urls)),
]
7 changes: 5 additions & 2 deletions blango/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blango.settings')


os.environ.setdefault("DJANGO_CONFIGURATION", "Prod")

from configurations.wsgi import get_wsgi_application

application = get_wsgi_application()
Empty file added blango_auth/__init__.py
Empty file.
Binary file added blango_auth/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added blango_auth/__pycache__/admin.cpython-36.pyc
Binary file not shown.
Binary file added blango_auth/__pycache__/apps.cpython-36.pyc
Binary file not shown.
Binary file added blango_auth/__pycache__/forms.cpython-36.pyc
Binary file not shown.
Binary file added blango_auth/__pycache__/models.cpython-36.pyc
Binary file not shown.
Binary file added blango_auth/__pycache__/views.cpython-36.pyc
Binary file not shown.
Loading